Skip to content

Commit 12724a7

Browse files
GarsooonRhysB
andauthored
Stop players /ignore'ing staff JPerms groups (#38)
* Stop players /ignore'ing staff JPerms groups * Update trial helper group name * Refactors ignore command for staff exemption Changes the ignore command to use the `essentials.ignore.exempt` permission instead of relying on JPerms for staff identification. This allows admins to easily configure staff members who cannot be ignored, regardless of their group membership. Also, ensures that exempted players are automatically unignored by all other players upon joining. * Code for /mail to get sent via Discord (#11) * Prototype code for /mail to get sent via Discord * Remove ] * Resolve stale pr conflicts * Versioning * Fix merge error * Enhances Discord mail integration Improves the Discord mail forwarding feature by: - Ensuring mail forwarding only occurs if both Discord plugins are enabled. - Preventing forwarding to online players. - Preventing forwarding to players who have disabled the feature. - Adds logging for successful and failed Discord mail attempts. - Fixes a typo in the UserData class that was preventing UUID's being set correctly. --------- Co-authored-by: Garsooon <carson12345678910@hotmail.com> Co-authored-by: Garsooon <46406077+Garsooon@users.noreply.github.com> * Resolve build issues * Stop players /ignore'ing staff JPerms groups * Update trial helper group name * Refactors ignore command for staff exemption Changes the ignore command to use the `essentials.ignore.exempt` permission instead of relying on JPerms for staff identification. This allows admins to easily configure staff members who cannot be ignored, regardless of their group membership. Also, ensures that exempted players are automatically unignored by all other players upon joining. * Make ignore check occur earlier --------- Co-authored-by: Rhys B <jetpackingwolf@gmail.com>
1 parent 5602482 commit 12724a7

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import java.util.logging.Level;
1818
import java.util.logging.Logger;
1919

20+
import static org.bukkit.Bukkit.getPlayer;
21+
2022

2123
public class EssentialsPlayerListener extends PlayerListener {
2224
private static final Logger LOGGER = Logger.getLogger("Minecraft");
@@ -41,6 +43,24 @@ public void onPlayerRespawn(final PlayerRespawnEvent event) {
4143
@Override
4244
public void onPlayerChat(final PlayerChatEvent event) {
4345
final User user = ess.getUser(event.getPlayer());
46+
47+
// If the user has ignore exempt permission, unignore them for all players
48+
if (user.hasPermission("essentials.ignore.exempt") || user.isOp()) {
49+
for (Player p : ess.getServer().getOnlinePlayers()) {
50+
// Skip self
51+
if(p.getName().equalsIgnoreCase(user.getName())) {
52+
continue;
53+
}
54+
55+
User u = ess.getUser(p);
56+
57+
// If the viewer is ignoring the poster, unignore them
58+
if (u.isIgnoredPlayer(user.getName())) {
59+
u.setIgnoredPlayer(user.getName(), false);
60+
}
61+
}
62+
}
63+
4464
if (user.isMuted()) {
4565
event.setCancelled(true);
4666
user.sendMessage(Util.i18n("playerMuted"));

Essentials/src/main/java/com/earth2me/essentials/commands/Commandignore.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,44 @@
22

33
import com.earth2me.essentials.User;
44
import com.earth2me.essentials.Util;
5+
import org.bukkit.ChatColor;
56
import org.bukkit.Server;
67

8+
import com.johnymuffin.jperms.beta.JohnyPerms;
9+
import com.johnymuffin.jperms.beta.JohnyPermsAPI;
10+
import com.johnymuffin.jperms.core.models.PermissionsUser;
11+
12+
import org.json.simple.JSONArray;
13+
import org.json.simple.JSONObject;
14+
import org.json.simple.parser.JSONParser;
15+
16+
import java.io.FileReader;
17+
import java.util.UUID;
718

819
public class Commandignore extends EssentialsCommand {
920

1021
public Commandignore() {
1122
super("ignore");
1223
}
1324

25+
private UUID getUUIDFromCache(String playerName) {
26+
try {
27+
JSONParser parser = new JSONParser();
28+
JSONArray arr = (JSONArray) parser.parse(new FileReader("uuidcache.json"));
29+
for (Object obj : arr) {
30+
JSONObject entry = (JSONObject) obj;
31+
String name = (String) entry.get("name");
32+
if (name != null && name.equalsIgnoreCase(playerName)) {
33+
String uuidStr = (String) entry.get("uuid");
34+
return UUID.fromString(uuidStr);
35+
}
36+
}
37+
} catch (Exception e) {
38+
// Sil
39+
}
40+
return null;
41+
}
42+
1443
@Override
1544
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception {
1645
if (args.length < 1) {
@@ -26,6 +55,13 @@ protected void run(Server server, User user, String commandLabel, String[] args)
2655
throw new Exception(Util.i18n("playerNotFound"));
2756
}
2857
String name = u.getName();
58+
59+
if(u.hasPermission("essentials.ignore.exempt") || u.isOp()) {
60+
user.setIgnoredPlayer(name, false); // Ensure they are not ignored. This is useful if an op/exempt player was ignored before gaining exempt status.
61+
user.sendMessage(Util.format("ignoreExempt", u.getName()));
62+
return;
63+
}
64+
2965
if (user.isIgnoredPlayer(name)) {
3066
user.setIgnoredPlayer(name, false);
3167
user.sendMessage(Util.format("unignorePlayer", u.getName()));
@@ -34,6 +70,4 @@ protected void run(Server server, User user, String commandLabel, String[] args)
3470
user.sendMessage(Util.format("ignorePlayer", u.getName()));
3571
}
3672
}
37-
38-
3973
}

Essentials/src/main/resources/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ unableToSpawnMob = Unable to spawn mob.
324324
unbannedIP = Unbanned IP address.
325325
unbannedPlayer = Unbanned player.
326326
unignorePlayer = You are not ignoring player {0} anymore.
327+
ignoreExempt = \u00a7cYou cannot ignore that player.
327328
unknownItemId = Unknown item id: {0}
328329
unknownItemInList = Unknown item {0} in {1} list.
329330
unknownItemName = Unknown item name: {0}

0 commit comments

Comments
 (0)