From ad28c8c85ef3b2e22cf63f43705f6489ebb1ef3d Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Fri, 3 Feb 2023 03:01:22 +0800 Subject: [PATCH 01/15] Rework + support whitelist enforcement --- .../skript/conditions/CondIsWhitelisted.java | 70 ++++++------- .../skript/expressions/ExprWhitelist.java | 98 ++++++++++++------- 2 files changed, 99 insertions(+), 69 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java index b4ba008561a..274ee329dae 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java @@ -19,7 +19,7 @@ package ch.njol.skript.conditions; import org.bukkit.Bukkit; -import org.bukkit.entity.Player; +import org.bukkit.OfflinePlayer; import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; @@ -27,6 +27,7 @@ import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.RequiredPlugins; import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Condition; import ch.njol.skript.lang.Expression; @@ -34,57 +35,56 @@ import ch.njol.util.Kleenean; @Name("Is Whitelisted") -@Description("Whether or not the server or a player is whitelisted.") -@Examples({"if server is whitelisted:", "if player is whitelisted"}) -@Since("2.5.2") +@Description("Whether or not the server or a player is whitelisted, and server is whitelist enforced.") +@Examples({ + "if player is whitelisted:", + "if server is whitelisted:", + "if server is whitelist enforced:" +}) +@Since("2.5.2, INSERT VERSION (enforce)") +@RequiredPlugins("Minecraft 1.17+") public class CondIsWhitelisted extends Condition { - + + private static final boolean ENFORCE_SUPPORT; + static { + ENFORCE_SUPPORT = Skript.methodExists(Bukkit.class, "isWhitelistEnforced"); Skript.registerCondition(CondIsWhitelisted.class, "[the] server (is|1¦is(n't| not)) white[ ]listed", - "%players% (is|are)(|1¦(n't| not)) white[ ]listed"); + "%offlineplayers% (is|are)(|1¦(n't| not)) white[ ]listed", + (ENFORCE_SUPPORT ? "[the] server (is|1¦is(n't| not)) white[ ]list enforced" : "")); } - + @Nullable - private Expression player; - + private Expression player; + private boolean isServer; - + private boolean isEnforce; + @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { setNegated(parseResult.mark == 1); - isServer = matchedPattern == 0; - if (matchedPattern == 1) - player = (Expression) exprs[0]; + if (matchedPattern == 0 || matchedPattern == 2) { + isServer = true; + isEnforce = matchedPattern == 2; + } + else if (matchedPattern == 1) + player = (Expression) exprs[0]; return true; } - + @Override - @SuppressWarnings("null") public boolean check(Event e) { if (isServer) - return Bukkit.hasWhitelist() == isNegated(); - Player[] players = player.getAll(e); - if (player.getAnd() && isNegated()) { - for (Player player : players) - if (player.isWhitelisted()) - return false; - } else if(player.getAnd()){ - for (Player player : players) - if (!player.isWhitelisted()) - return false; - } else { - for (Player player: players) - if(player.isWhitelisted()) - return !isNegated(); - } - return !isNegated(); + return (isEnforce ? Bukkit.isWhitelistEnforced() : Bukkit.hasWhitelist()) ^ isNegated(); + + return player.check(e, OfflinePlayer::isWhitelisted, isNegated()); } - + @Override - @SuppressWarnings("null") public String toString(@Nullable Event e, boolean debug) { - return (player.getSingle(e) != null ? "player" : "server") + (isNegated() ? "not" : "") + " whitelisted"; + return (isServer ? "server" : "player") + " is " + (isNegated() ? "not" : "") + " " + + (isEnforce ? "whitelist enforced" : "whitelisted"); } - + } diff --git a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java index 12e24e00d4f..28c5e3b47eb 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java +++ b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java @@ -21,6 +21,7 @@ import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; @@ -29,6 +30,7 @@ import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.RequiredPlugins; import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.ExpressionType; @@ -38,83 +40,111 @@ import ch.njol.util.coll.CollectionUtils; @Name("Whitelist") -@Description("A server's whitelist." + - "This expression can be used to add/remove players to/from the whitelist," + - " to enable it and disable it (set whitelist to true / set whitelist to false)," + - " and to empty it (reset whitelist)") +@Description({"A server's whitelist." + + "This expression can be used to add/remove players to/from the whitelist.", + "To enable and disable it (set whitelist to true / set whitelist to false), and to empty it (reset whitelist)", + "To enable and disable enforcement (set whitelist enforcement to true / set whitelist enforcement to false),", + "which kicks all non-whitelisted players once set to true." +}) @Examples({"set whitelist to false", "add all players to whitelist", "reset the whitelist"}) -@Since("2.5.2") +@Since("2.5.2, INSERT VERSION (enforce)") +@RequiredPlugins("Minecraft 1.17+") public class ExprWhitelist extends SimpleExpression { - + + private static final boolean ENFORCE_SUPPORT; + static { - Skript.registerExpression(ExprWhitelist.class, OfflinePlayer.class, ExpressionType.SIMPLE, "[the] white[ ]list"); + ENFORCE_SUPPORT = Skript.methodExists(Bukkit.class, "setWhitelistEnforced", boolean.class); + Skript.registerExpression(ExprWhitelist.class, OfflinePlayer.class, ExpressionType.SIMPLE, "[the] white[ ]list" + + (ENFORCE_SUPPORT ? " [:enforcement]" : "")); } - + + private boolean isEnforce; + @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + isEnforce = parseResult.hasTag("enforcement"); return true; } - - @Nullable + @Override protected OfflinePlayer[] get(Event e) { - return Bukkit.getServer().getWhitelistedPlayers().toArray(new OfflinePlayer[0]); + return (!isEnforce ? Bukkit.getServer().getWhitelistedPlayers().toArray(new OfflinePlayer[0]) : new OfflinePlayer[0]); } - - @Nullable + @Override public Class[] acceptChange(ChangeMode mode) { - if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) + if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { + if (isEnforce) { + if (ENFORCE_SUPPORT) + Skript.error("\"Whitelist enforcement\" can't have anything " + (mode == ChangeMode.ADD ? "added" : "removed") + "." + + " Use 'whitelist' instead."); + return null; + } return CollectionUtils.array(OfflinePlayer[].class); - else if (mode == ChangeMode.SET || mode == ChangeMode.RESET) + } else if (mode == ChangeMode.SET || mode == ChangeMode.RESET) { + if (mode == ChangeMode.RESET && isEnforce) + return null; return CollectionUtils.array(Boolean.class); - else - return null; + } + return null; } - + @Override public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { switch (mode) { case SET: - if (delta != null) - Bukkit.setWhitelist((Boolean) delta[0]); + boolean value = (boolean) delta[0]; + if (isEnforce) + Bukkit.setWhitelistEnforced(value); + else + Bukkit.setWhitelist(value); + if (ENFORCE_SUPPORT) + reloadWhitelist(); break; case ADD: - if (delta != null) { - for (Object p : delta) - ((OfflinePlayer) p).setWhitelisted(true); - } + for (Object p : delta) + ((OfflinePlayer) p).setWhitelisted(true); break; case REMOVE: - if (delta != null) { - for (Object p : delta) - ((OfflinePlayer) p).setWhitelisted(false); - } + for (Object p : delta) + ((OfflinePlayer) p).setWhitelisted(false); + if (ENFORCE_SUPPORT) + reloadWhitelist(); break; case RESET: - for (OfflinePlayer p : Bukkit.getWhitelistedPlayers()) + for (OfflinePlayer p : Bukkit.getWhitelistedPlayers()) { p.setWhitelisted(false); + } break; default: assert false; } } - + + private void reloadWhitelist() { + Bukkit.reloadWhitelist(); + for (Player player : Bukkit.getOnlinePlayers()) { + if (!player.isWhitelisted() && !player.isOp()) + player.kickPlayer("You are not whitelisted on this server!"); + } + } + @Override public boolean isSingle() { return false; } - + @Override public Class getReturnType() { return OfflinePlayer.class; } - + @Override public String toString(@Nullable Event e, boolean debug) { - return "whitelist"; + return "whitelist" + (isEnforce ? " enforcement" : ""); } - + } From c2c7370a7cf7445baafbf2aee75a7db331ee1f17 Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Fri, 3 Feb 2023 03:07:29 +0800 Subject: [PATCH 02/15] Simple reformat --- .../ch/njol/skript/conditions/CondIsWhitelisted.java | 6 +++--- .../java/ch/njol/skript/expressions/ExprWhitelist.java | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java index 274ee329dae..57443a5c065 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java @@ -74,15 +74,15 @@ else if (matchedPattern == 1) } @Override - public boolean check(Event e) { + public boolean check(Event event) { if (isServer) return (isEnforce ? Bukkit.isWhitelistEnforced() : Bukkit.hasWhitelist()) ^ isNegated(); - return player.check(e, OfflinePlayer::isWhitelisted, isNegated()); + return player.check(event, OfflinePlayer::isWhitelisted, isNegated()); } @Override - public String toString(@Nullable Event e, boolean debug) { + public String toString(@Nullable Event event, boolean debug) { return (isServer ? "server" : "player") + " is " + (isNegated() ? "not" : "") + " " + (isEnforce ? "whitelist enforced" : "whitelisted"); } diff --git a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java index 28c5e3b47eb..b9196de465c 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java +++ b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java @@ -40,7 +40,8 @@ import ch.njol.util.coll.CollectionUtils; @Name("Whitelist") -@Description({"A server's whitelist." + +@Description({ + "A server's whitelist or whitelist enforcement.", "This expression can be used to add/remove players to/from the whitelist.", "To enable and disable it (set whitelist to true / set whitelist to false), and to empty it (reset whitelist)", "To enable and disable enforcement (set whitelist enforcement to true / set whitelist enforcement to false),", @@ -70,7 +71,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye } @Override - protected OfflinePlayer[] get(Event e) { + protected OfflinePlayer[] get(Event event) { return (!isEnforce ? Bukkit.getServer().getWhitelistedPlayers().toArray(new OfflinePlayer[0]) : new OfflinePlayer[0]); } @@ -93,7 +94,7 @@ public Class[] acceptChange(ChangeMode mode) { } @Override - public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { + public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { switch (mode) { case SET: boolean value = (boolean) delta[0]; @@ -143,7 +144,7 @@ public Class getReturnType() { } @Override - public String toString(@Nullable Event e, boolean debug) { + public String toString(@Nullable Event event, boolean debug) { return "whitelist" + (isEnforce ? " enforcement" : ""); } From 49f8e301867cce0578d08063f1dc605947e3d03d Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Sat, 4 Feb 2023 22:05:53 +0800 Subject: [PATCH 03/15] Requested changes + new effect --- .../skript/conditions/CondIsWhitelisted.java | 33 +++---- .../skript/effects/EffEnforceWhitelist.java | 93 +++++++++++++++++++ .../skript/expressions/ExprWhitelist.java | 70 ++++---------- 3 files changed, 128 insertions(+), 68 deletions(-) create mode 100644 src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java diff --git a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java index 57443a5c065..8349e9147ca 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java @@ -41,35 +41,33 @@ "if server is whitelisted:", "if server is whitelist enforced:" }) -@Since("2.5.2, INSERT VERSION (enforce)") -@RequiredPlugins("Minecraft 1.17+") +@Since("2.5.2, INSERT VERSION (enforce, offline players)") +@RequiredPlugins("Minecraft 1.17+ (enforce)") public class CondIsWhitelisted extends Condition { - private static final boolean ENFORCE_SUPPORT; + private static final boolean ENFORCE_SUPPORT = Skript.methodExists(Bukkit.class, "isWhitelistEnforced"); static { - ENFORCE_SUPPORT = Skript.methodExists(Bukkit.class, "isWhitelistEnforced"); Skript.registerCondition(CondIsWhitelisted.class, - "[the] server (is|1¦is(n't| not)) white[ ]listed", - "%offlineplayers% (is|are)(|1¦(n't| not)) white[ ]listed", - (ENFORCE_SUPPORT ? "[the] server (is|1¦is(n't| not)) white[ ]list enforced" : "")); + "[the] server (is|not:(isn't|is not)) white[ ]listed", + "%offlineplayers% (is|are)(|not:(isn't|is not)) white[ ]listed", + (ENFORCE_SUPPORT ? "[the] white[ ]list (is|not:(isn't|is not)) enforced" : "") + ); } @Nullable - private Expression player; + private Expression players; private boolean isServer; private boolean isEnforce; @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - setNegated(parseResult.mark == 1); - if (matchedPattern == 0 || matchedPattern == 2) { - isServer = true; - isEnforce = matchedPattern == 2; - } - else if (matchedPattern == 1) - player = (Expression) exprs[0]; + setNegated(parseResult.hasTag("not")); + isServer = matchedPattern != 1; + isEnforce = matchedPattern == 2; + if (matchedPattern == 1) + players = (Expression) exprs[0]; return true; } @@ -77,13 +75,12 @@ else if (matchedPattern == 1) public boolean check(Event event) { if (isServer) return (isEnforce ? Bukkit.isWhitelistEnforced() : Bukkit.hasWhitelist()) ^ isNegated(); - - return player.check(event, OfflinePlayer::isWhitelisted, isNegated()); + return players.check(event, OfflinePlayer::isWhitelisted, isNegated()); } @Override public String toString(@Nullable Event event, boolean debug) { - return (isServer ? "server" : "player") + " is " + (isNegated() ? "not" : "") + " " + return (players != null ? players.toString(event, debug) : "server") + " is " + (isNegated() ? "not" : "") + " " + (isEnforce ? "whitelist enforced" : "whitelisted"); } diff --git a/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java b/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java new file mode 100644 index 00000000000..1a96c236819 --- /dev/null +++ b/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java @@ -0,0 +1,93 @@ +/** + * This file is part of Skript. + * + * Skript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Skript is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Skript. If not, see . + * + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +package ch.njol.skript.effects; + +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; + +import java.io.File; + +import ch.njol.skript.Skript; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Since; +import ch.njol.skript.doc.RequiredPlugins; +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.util.Utils; +import ch.njol.util.Kleenean; + +@Name("Enforce Whitelist") +@Description("Enforces or un-enforce a server's whitelist. All non-whitelisted players will be kicked upon enforcing the whitelist.") +@Examples({ + "enforce the whitelist", + "unenforce the whitelist" +}) +@Since("INSERT VERSION") +@RequiredPlugins("Minecraft 1.17+") +public class EffEnforceWhitelist extends Effect { + + private static String NOT_WHITELISTED_MESSAGE = "You are not whitelisted on this server!"; + + static { + try { + YamlConfiguration spigotYml = YamlConfiguration.loadConfiguration(new File("spigot.yml")); + NOT_WHITELISTED_MESSAGE = (String) spigotYml.get("messages.whitelist", NOT_WHITELISTED_MESSAGE); + } catch (Exception ignored) {} + if (Skript.methodExists(Bukkit.class, "setWhitelistEnforced", boolean.class)) + Skript.registerEffect(EffEnforceWhitelist.class, "[:un]enforce [the] white[ ]list"); + } + + private boolean enforce; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + enforce = !parseResult.hasTag("un"); + return true; + } + + @Override + protected void execute(Event event) { + Bukkit.setWhitelistEnforced(enforce); + reloadWhitelist(); + } + + // A workaround for Bukkit's not kicking non-whitelisted players upon enforcement + public void reloadWhitelist() { + Bukkit.reloadWhitelist(); + if (!Bukkit.hasWhitelist() || !Bukkit.isWhitelistEnforced()) + return; + for (Player player : Bukkit.getOnlinePlayers()) { + if (!player.isWhitelisted() && !player.isOp()) + player.kickPlayer(Utils.replaceChatStyles(NOT_WHITELISTED_MESSAGE)); + } + } + + @Override + public String toString(@Nullable Event e, boolean debug) { + return (!enforce ? "un" : "") + "enforce the whitelist"; + } + +} diff --git a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java index b9196de465c..f2f5c99885b 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java +++ b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java @@ -19,9 +19,9 @@ */ package ch.njol.skript.expressions; +import ch.njol.skript.effects.EffEnforceWhitelist; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; @@ -30,7 +30,6 @@ import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.RequiredPlugins; import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.ExpressionType; @@ -41,53 +40,39 @@ @Name("Whitelist") @Description({ - "A server's whitelist or whitelist enforcement.", + "A server's whitelist.", "This expression can be used to add/remove players to/from the whitelist.", - "To enable and disable it (set whitelist to true / set whitelist to false), and to empty it (reset whitelist)", - "To enable and disable enforcement (set whitelist enforcement to true / set whitelist enforcement to false),", - "which kicks all non-whitelisted players once set to true." + "To enable and disable it (set whitelist to true/false), and to empty it (reset whitelist)" }) -@Examples({"set whitelist to false", +@Examples({ + "set whitelist to false", "add all players to whitelist", - "reset the whitelist"}) -@Since("2.5.2, INSERT VERSION (enforce)") -@RequiredPlugins("Minecraft 1.17+") + "reset the whitelist" +}) +@Since("2.5.2") public class ExprWhitelist extends SimpleExpression { - private static final boolean ENFORCE_SUPPORT; + private EffEnforceWhitelist effEnforceWhitelist = new EffEnforceWhitelist(); static { - ENFORCE_SUPPORT = Skript.methodExists(Bukkit.class, "setWhitelistEnforced", boolean.class); - Skript.registerExpression(ExprWhitelist.class, OfflinePlayer.class, ExpressionType.SIMPLE, "[the] white[ ]list" - + (ENFORCE_SUPPORT ? " [:enforcement]" : "")); + Skript.registerExpression(ExprWhitelist.class, OfflinePlayer.class, ExpressionType.SIMPLE, "[the] white[ ]list"); } - private boolean isEnforce; - @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - isEnforce = parseResult.hasTag("enforcement"); return true; } @Override protected OfflinePlayer[] get(Event event) { - return (!isEnforce ? Bukkit.getServer().getWhitelistedPlayers().toArray(new OfflinePlayer[0]) : new OfflinePlayer[0]); + return Bukkit.getServer().getWhitelistedPlayers().toArray(new OfflinePlayer[0]); } @Override public Class[] acceptChange(ChangeMode mode) { if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { - if (isEnforce) { - if (ENFORCE_SUPPORT) - Skript.error("\"Whitelist enforcement\" can't have anything " + (mode == ChangeMode.ADD ? "added" : "removed") + "." + - " Use 'whitelist' instead."); - return null; - } return CollectionUtils.array(OfflinePlayer[].class); } else if (mode == ChangeMode.SET || mode == ChangeMode.RESET) { - if (mode == ChangeMode.RESET && isEnforce) - return null; return CollectionUtils.array(Boolean.class); } return null; @@ -97,27 +82,20 @@ public Class[] acceptChange(ChangeMode mode) { public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { switch (mode) { case SET: - boolean value = (boolean) delta[0]; - if (isEnforce) - Bukkit.setWhitelistEnforced(value); - else - Bukkit.setWhitelist(value); - if (ENFORCE_SUPPORT) - reloadWhitelist(); + Bukkit.setWhitelist((Boolean) delta[0]); + effEnforceWhitelist.reloadWhitelist(); break; case ADD: - for (Object p : delta) - ((OfflinePlayer) p).setWhitelisted(true); + for (Object player : delta) + ((OfflinePlayer) player).setWhitelisted(true); break; case REMOVE: - for (Object p : delta) - ((OfflinePlayer) p).setWhitelisted(false); - if (ENFORCE_SUPPORT) - reloadWhitelist(); + for (Object player : delta) + ((OfflinePlayer) player).setWhitelisted(false); break; case RESET: - for (OfflinePlayer p : Bukkit.getWhitelistedPlayers()) { - p.setWhitelisted(false); + for (OfflinePlayer player : Bukkit.getWhitelistedPlayers()) { + player.setWhitelisted(false); } break; default: @@ -125,14 +103,6 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { } } - private void reloadWhitelist() { - Bukkit.reloadWhitelist(); - for (Player player : Bukkit.getOnlinePlayers()) { - if (!player.isWhitelisted() && !player.isOp()) - player.kickPlayer("You are not whitelisted on this server!"); - } - } - @Override public boolean isSingle() { return false; @@ -145,7 +115,7 @@ public Class getReturnType() { @Override public String toString(@Nullable Event event, boolean debug) { - return "whitelist" + (isEnforce ? " enforcement" : ""); + return "whitelist"; } } From 281f987b702347d1091a561161f045d08b47c81a Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Sat, 11 Feb 2023 21:33:41 +0800 Subject: [PATCH 04/15] Requested changes --- .../njol/skript/conditions/CondIsWhitelisted.java | 2 +- .../ch/njol/skript/effects/EffEnforceWhitelist.java | 13 +++++++------ .../ch/njol/skript/expressions/ExprWhitelist.java | 13 ++++++++----- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java index 8349e9147ca..c239563e25d 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java @@ -35,7 +35,7 @@ import ch.njol.util.Kleenean; @Name("Is Whitelisted") -@Description("Whether or not the server or a player is whitelisted, and server is whitelist enforced.") +@Description("Whether or not the server or a player is whitelisted, or the server is whitelist enforced.") @Examples({ "if player is whitelisted:", "if server is whitelisted:", diff --git a/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java b/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java index 1a96c236819..840a16bddb1 100644 --- a/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java +++ b/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java @@ -52,12 +52,13 @@ public class EffEnforceWhitelist extends Effect { private static String NOT_WHITELISTED_MESSAGE = "You are not whitelisted on this server!"; static { - try { - YamlConfiguration spigotYml = YamlConfiguration.loadConfiguration(new File("spigot.yml")); - NOT_WHITELISTED_MESSAGE = (String) spigotYml.get("messages.whitelist", NOT_WHITELISTED_MESSAGE); - } catch (Exception ignored) {} - if (Skript.methodExists(Bukkit.class, "setWhitelistEnforced", boolean.class)) + if (Skript.methodExists(Bukkit.class, "setWhitelistEnforced", boolean.class)) { + try { + YamlConfiguration spigotYml = YamlConfiguration.loadConfiguration(new File("spigot.yml")); + NOT_WHITELISTED_MESSAGE = (String) spigotYml.get("messages.whitelist", NOT_WHITELISTED_MESSAGE); + } catch (Exception ignored) {} Skript.registerEffect(EffEnforceWhitelist.class, "[:un]enforce [the] white[ ]list"); + } } private boolean enforce; @@ -75,7 +76,7 @@ protected void execute(Event event) { } // A workaround for Bukkit's not kicking non-whitelisted players upon enforcement - public void reloadWhitelist() { + public static void reloadWhitelist() { Bukkit.reloadWhitelist(); if (!Bukkit.hasWhitelist() || !Bukkit.isWhitelistEnforced()) return; diff --git a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java index f2f5c99885b..9697cdff87b 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java +++ b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java @@ -52,8 +52,6 @@ @Since("2.5.2") public class ExprWhitelist extends SimpleExpression { - private EffEnforceWhitelist effEnforceWhitelist = new EffEnforceWhitelist(); - static { Skript.registerExpression(ExprWhitelist.class, OfflinePlayer.class, ExpressionType.SIMPLE, "[the] white[ ]list"); } @@ -79,11 +77,15 @@ public Class[] acceptChange(ChangeMode mode) { } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { + if (delta == null && mode != ChangeMode.RESET) + return; switch (mode) { case SET: - Bukkit.setWhitelist((Boolean) delta[0]); - effEnforceWhitelist.reloadWhitelist(); + boolean value = (Boolean) delta[0]; + Bukkit.setWhitelist(value); + if (value) + EffEnforceWhitelist.reloadWhitelist(); break; case ADD: for (Object player : delta) @@ -92,6 +94,7 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { case REMOVE: for (Object player : delta) ((OfflinePlayer) player).setWhitelisted(false); + EffEnforceWhitelist.reloadWhitelist(); break; case RESET: for (OfflinePlayer player : Bukkit.getWhitelistedPlayers()) { From 8e72b7780d688c2161abbd139481e0ba4865898a Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Sat, 11 Feb 2023 23:24:49 +0800 Subject: [PATCH 05/15] Requested changes --- src/main/java/ch/njol/skript/expressions/ExprWhitelist.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java index 9697cdff87b..5033a7d002e 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java +++ b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java @@ -40,7 +40,7 @@ @Name("Whitelist") @Description({ - "A server's whitelist.", + "The server's whitelist.", "This expression can be used to add/remove players to/from the whitelist.", "To enable and disable it (set whitelist to true/false), and to empty it (reset whitelist)" }) From 98655ad55a06bf7d1ec10c9b636e549b6e9c8bcf Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Mon, 13 Feb 2023 18:55:01 +0800 Subject: [PATCH 06/15] Fix pattern --- .../njol/skript/conditions/CondIsWhitelisted.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java index c239563e25d..6d166c88604 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java @@ -34,6 +34,9 @@ import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; +import java.util.ArrayList; +import java.util.List; + @Name("Is Whitelisted") @Description("Whether or not the server or a player is whitelisted, or the server is whitelist enforced.") @Examples({ @@ -48,11 +51,12 @@ public class CondIsWhitelisted extends Condition { private static final boolean ENFORCE_SUPPORT = Skript.methodExists(Bukkit.class, "isWhitelistEnforced"); static { - Skript.registerCondition(CondIsWhitelisted.class, - "[the] server (is|not:(isn't|is not)) white[ ]listed", - "%offlineplayers% (is|are)(|not:(isn't|is not)) white[ ]listed", - (ENFORCE_SUPPORT ? "[the] white[ ]list (is|not:(isn't|is not)) enforced" : "") - ); + List patterns = new ArrayList<>(); + patterns.add("[the] server (is|not:(isn't|is not)) white[ ]listed"); + patterns.add("%offlineplayers% (is|are|not:(isn't|is not|aren't|are not)) white[ ]listed"); + if (ENFORCE_SUPPORT) + patterns.add("[the] white[ ]list (is|not:(isn't|is not)) enforced"); + Skript.registerCondition(CondIsWhitelisted.class, patterns.toArray(new String[0])); } @Nullable From c4d26bdbe67eaf123dccfb298130a68585aa4734 Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Wed, 3 May 2023 01:24:49 +0800 Subject: [PATCH 07/15] Requested change --- .../njol/skript/conditions/CondIsWhitelisted.java | 5 +++-- .../njol/skript/effects/EffEnforceWhitelist.java | 5 ++++- .../ch/njol/skript/expressions/ExprWhitelist.java | 14 +++++++------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java index 6d166c88604..3144383372f 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java @@ -66,6 +66,7 @@ public class CondIsWhitelisted extends Condition { private boolean isEnforce; @Override + @SuppressWarnings("unchecked") public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { setNegated(parseResult.hasTag("not")); isServer = matchedPattern != 1; @@ -84,8 +85,8 @@ public boolean check(Event event) { @Override public String toString(@Nullable Event event, boolean debug) { - return (players != null ? players.toString(event, debug) : "server") + " is " + (isNegated() ? "not" : "") + " " - + (isEnforce ? "whitelist enforced" : "whitelisted"); + return (players != null ? players.toString(event, debug) : "server") + " is " + (isNegated() ? "not " : " ") + + (isEnforce ? "whitelist enforced" : "whitelisted"); } } diff --git a/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java b/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java index 840a16bddb1..fc108c7214f 100644 --- a/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java +++ b/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java @@ -40,7 +40,10 @@ import ch.njol.util.Kleenean; @Name("Enforce Whitelist") -@Description("Enforces or un-enforce a server's whitelist. All non-whitelisted players will be kicked upon enforcing the whitelist.") +@Description({ + "Enforces or un-enforce a server's whitelist.", + "All non-whitelisted players will be kicked upon enforcing the whitelist." +}) @Examples({ "enforce the whitelist", "unenforce the whitelist" diff --git a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java index 5033a7d002e..aff47fc75a8 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java +++ b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java @@ -70,7 +70,7 @@ protected OfflinePlayer[] get(Event event) { public Class[] acceptChange(ChangeMode mode) { if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { return CollectionUtils.array(OfflinePlayer[].class); - } else if (mode == ChangeMode.SET || mode == ChangeMode.RESET) { + } else if (mode == ChangeMode.SET || mode == ChangeMode.RESET || mode == ChangeMode.DELETE) { return CollectionUtils.array(Boolean.class); } return null; @@ -78,13 +78,13 @@ public Class[] acceptChange(ChangeMode mode) { @Override public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { - if (delta == null && mode != ChangeMode.RESET) + if (delta == null && mode != ChangeMode.DELETE && mode != ChangeMode.RESET) return; switch (mode) { case SET: - boolean value = (Boolean) delta[0]; - Bukkit.setWhitelist(value); - if (value) + boolean toggle = (Boolean) delta[0]; + Bukkit.setWhitelist(toggle); + if (toggle) EffEnforceWhitelist.reloadWhitelist(); break; case ADD: @@ -96,10 +96,10 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { ((OfflinePlayer) player).setWhitelisted(false); EffEnforceWhitelist.reloadWhitelist(); break; + case DELETE: case RESET: - for (OfflinePlayer player : Bukkit.getWhitelistedPlayers()) { + for (OfflinePlayer player : Bukkit.getWhitelistedPlayers()) player.setWhitelisted(false); - } break; default: assert false; From 2201fdc0a0e897340b381dc1ad6d138e672fa70a Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Wed, 3 May 2023 01:26:18 +0800 Subject: [PATCH 08/15] Fix docs --- src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java | 2 +- src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java | 2 +- src/main/java/ch/njol/skript/expressions/ExprWhitelist.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java index 3144383372f..f4a007c182d 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java @@ -45,7 +45,7 @@ "if server is whitelist enforced:" }) @Since("2.5.2, INSERT VERSION (enforce, offline players)") -@RequiredPlugins("Minecraft 1.17+ (enforce)") +@RequiredPlugins("MC 1.17+ (enforce)") public class CondIsWhitelisted extends Condition { private static final boolean ENFORCE_SUPPORT = Skript.methodExists(Bukkit.class, "isWhitelistEnforced"); diff --git a/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java b/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java index fc108c7214f..de2ec7887bf 100644 --- a/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java +++ b/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java @@ -49,7 +49,7 @@ "unenforce the whitelist" }) @Since("INSERT VERSION") -@RequiredPlugins("Minecraft 1.17+") +@RequiredPlugins("MC 1.17+") public class EffEnforceWhitelist extends Effect { private static String NOT_WHITELISTED_MESSAGE = "You are not whitelisted on this server!"; diff --git a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java index aff47fc75a8..d55c34c33d1 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java +++ b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java @@ -49,7 +49,7 @@ "add all players to whitelist", "reset the whitelist" }) -@Since("2.5.2") +@Since("2.5.2, INSERT VERSION (delete)") public class ExprWhitelist extends SimpleExpression { static { From 43e7190b5bb20f1765003b5973f6d1de533644c9 Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Wed, 3 May 2023 01:27:35 +0800 Subject: [PATCH 09/15] Fix docs --- src/main/java/ch/njol/skript/expressions/ExprWhitelist.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java index d55c34c33d1..a4f0889e6bf 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java +++ b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java @@ -70,7 +70,7 @@ protected OfflinePlayer[] get(Event event) { public Class[] acceptChange(ChangeMode mode) { if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { return CollectionUtils.array(OfflinePlayer[].class); - } else if (mode == ChangeMode.SET || mode == ChangeMode.RESET || mode == ChangeMode.DELETE) { + } else if (mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { return CollectionUtils.array(Boolean.class); } return null; From 61fec469abc89df62b8608a68c551f77e94f5e8f Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Wed, 10 May 2023 03:14:18 +0800 Subject: [PATCH 10/15] Requested change --- .../ch/njol/skript/conditions/CondIsWhitelisted.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java index f4a007c182d..af708d575d8 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java @@ -51,12 +51,12 @@ public class CondIsWhitelisted extends Condition { private static final boolean ENFORCE_SUPPORT = Skript.methodExists(Bukkit.class, "isWhitelistEnforced"); static { - List patterns = new ArrayList<>(); - patterns.add("[the] server (is|not:(isn't|is not)) white[ ]listed"); - patterns.add("%offlineplayers% (is|are|not:(isn't|is not|aren't|are not)) white[ ]listed"); + String[] patterns = new String[ENFORCE_SUPPORT ? 3 : 2]; + patterns[0] = "[the] server (is|not:(isn't|is not)) white[ ]listed"; + patterns[1] = "%offlineplayers% (is|are|not:(isn't|is not|aren't|are not)) white[ ]listed"; if (ENFORCE_SUPPORT) - patterns.add("[the] white[ ]list (is|not:(isn't|is not)) enforced"); - Skript.registerCondition(CondIsWhitelisted.class, patterns.toArray(new String[0])); + patterns[2] = "[the] white[ ]list (is|not:(isn't|is not)) enforced"; + Skript.registerCondition(CondIsWhitelisted.class, patterns); } @Nullable From 2e72318cec5156827a28eacf93684c1c2772b3b2 Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Fri, 11 Aug 2023 20:54:41 +0800 Subject: [PATCH 11/15] Fix patterns for server whitelist --- .../skript/conditions/CondIsWhitelisted.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java index af708d575d8..579f444e64c 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java @@ -18,11 +18,6 @@ */ package ch.njol.skript.conditions; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; - import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; @@ -33,9 +28,10 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; - -import java.util.ArrayList; -import java.util.List; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; @Name("Is Whitelisted") @Description("Whether or not the server or a player is whitelisted, or the server is whitelist enforced.") @@ -52,10 +48,10 @@ public class CondIsWhitelisted extends Condition { static { String[] patterns = new String[ENFORCE_SUPPORT ? 3 : 2]; - patterns[0] = "[the] server (is|not:(isn't|is not)) white[ ]listed"; + patterns[0] = "[the] server (is|not:(isn't|is not)) (in white[ ]list mode|white[ ]listed)"; patterns[1] = "%offlineplayers% (is|are|not:(isn't|is not|aren't|are not)) white[ ]listed"; if (ENFORCE_SUPPORT) - patterns[2] = "[the] white[ ]list (is|not:(isn't|is not)) enforced"; + patterns[2] = "[the] server white[ ]list (is|not:(isn't|is not)) enforced"; Skript.registerCondition(CondIsWhitelisted.class, patterns); } From 732feba72cbb0869cbabb4784a94f4538f43c02f Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Thu, 4 Jan 2024 20:07:05 +0800 Subject: [PATCH 12/15] Fix examples & requested changes --- .../skript/conditions/CondIsWhitelisted.java | 16 +++++++++++----- .../njol/skript/expressions/ExprWhitelist.java | 18 ++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java index 579f444e64c..e0d50f25c33 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsWhitelisted.java @@ -36,9 +36,9 @@ @Name("Is Whitelisted") @Description("Whether or not the server or a player is whitelisted, or the server is whitelist enforced.") @Examples({ - "if player is whitelisted:", - "if server is whitelisted:", - "if server is whitelist enforced:" + "if the player is whitelisted:", + "if the server is whitelisted:", + "if the server whitelist is enforced:" }) @Since("2.5.2, INSERT VERSION (enforce, offline players)") @RequiredPlugins("MC 1.17+ (enforce)") @@ -81,8 +81,14 @@ public boolean check(Event event) { @Override public String toString(@Nullable Event event, boolean debug) { - return (players != null ? players.toString(event, debug) : "server") + " is " + (isNegated() ? "not " : " ") - + (isEnforce ? "whitelist enforced" : "whitelisted"); + String negation = isNegated() ? "not" : ""; + if (isServer) { + if (isEnforce) { + return "the server whitelist is " + negation + " enforced"; + } + return "the server is " + negation + " whitelisted"; + } + return players.toString(event, debug) + " is " + negation + " whitelisted"; } } diff --git a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java index a4f0889e6bf..ff6a23690eb 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java +++ b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java @@ -45,7 +45,7 @@ "To enable and disable it (set whitelist to true/false), and to empty it (reset whitelist)" }) @Examples({ - "set whitelist to false", + "set the whitelist to false", "add all players to whitelist", "reset the whitelist" }) @@ -68,18 +68,20 @@ protected OfflinePlayer[] get(Event event) { @Override public Class[] acceptChange(ChangeMode mode) { - if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { - return CollectionUtils.array(OfflinePlayer[].class); - } else if (mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { - return CollectionUtils.array(Boolean.class); - } + switch (mode) { + case ADD: + case REMOVE: + return CollectionUtils.array(OfflinePlayer.class); + case DELETE: + case RESET: + case SET: + return CollectionUtils.array(Boolean.class); + } return null; } @Override public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { - if (delta == null && mode != ChangeMode.DELETE && mode != ChangeMode.RESET) - return; switch (mode) { case SET: boolean toggle = (Boolean) delta[0]; From 3bd0f2f91593b91030d1637e14b832ea2874e955 Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Sat, 6 Jan 2024 19:44:58 +0800 Subject: [PATCH 13/15] Improve pattern --- src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java b/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java index de2ec7887bf..cce18cb3cd9 100644 --- a/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java +++ b/src/main/java/ch/njol/skript/effects/EffEnforceWhitelist.java @@ -58,9 +58,9 @@ public class EffEnforceWhitelist extends Effect { if (Skript.methodExists(Bukkit.class, "setWhitelistEnforced", boolean.class)) { try { YamlConfiguration spigotYml = YamlConfiguration.loadConfiguration(new File("spigot.yml")); - NOT_WHITELISTED_MESSAGE = (String) spigotYml.get("messages.whitelist", NOT_WHITELISTED_MESSAGE); + NOT_WHITELISTED_MESSAGE = spigotYml.getString("messages.whitelist", NOT_WHITELISTED_MESSAGE); } catch (Exception ignored) {} - Skript.registerEffect(EffEnforceWhitelist.class, "[:un]enforce [the] white[ ]list"); + Skript.registerEffect(EffEnforceWhitelist.class, "[:un]enforce [the] [server] white[ ]list"); } } From e9de32b7735485eed5c8ec71c28e226c0bb56618 Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Sat, 6 Jan 2024 19:45:12 +0800 Subject: [PATCH 14/15] Add tests --- .../syntaxes/expressions/ExprWhitelist.sk | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprWhitelist.sk diff --git a/src/test/skript/tests/syntaxes/expressions/ExprWhitelist.sk b/src/test/skript/tests/syntaxes/expressions/ExprWhitelist.sk new file mode 100644 index 00000000000..d1760c9b9e8 --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprWhitelist.sk @@ -0,0 +1,18 @@ +test "whitelist": + reset whitelist + set {_player} to "Njol" parsed as offline player + add {_player} to whitelist + assert {_player} is whitelisted with "Failed to whitelist a player" + + remove {_player} from whitelist + assert {_player} is not whitelisted with "Failed to remove a player from whitelist" + + add {_player} to whitelist + reset whitelist + assert whitelist is not set with "Failed to empty whitelist" + +test "enforce whitelist" when running minecraft "1.17": + enforce whitelist + assert server whitelist is enforced with "Failed to enforce server whitelist" + unenforce whitelist + assert server whitelist is not enforced with "Failed to unenforce whitelist" \ No newline at end of file From de53ecadd59a694623f7eb43ebf67067da26c4ac Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Sat, 13 Jan 2024 15:29:22 +0800 Subject: [PATCH 15/15] Improve formatting of test and ExprWhitelist description --- src/main/java/ch/njol/skript/expressions/ExprWhitelist.java | 6 +++--- src/test/skript/tests/syntaxes/expressions/ExprWhitelist.sk | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java index ff6a23690eb..e85a7ce345a 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java +++ b/src/main/java/ch/njol/skript/expressions/ExprWhitelist.java @@ -40,9 +40,9 @@ @Name("Whitelist") @Description({ - "The server's whitelist.", - "This expression can be used to add/remove players to/from the whitelist.", - "To enable and disable it (set whitelist to true/false), and to empty it (reset whitelist)" + "An expression for obtaining and modifying the server's whitelist.", + "Players may be added and removed from the whitelist.", + "The whitelist can be enabled or disabled by setting the whitelist to true or false respectively." }) @Examples({ "set the whitelist to false", diff --git a/src/test/skript/tests/syntaxes/expressions/ExprWhitelist.sk b/src/test/skript/tests/syntaxes/expressions/ExprWhitelist.sk index d1760c9b9e8..32aa528320e 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprWhitelist.sk +++ b/src/test/skript/tests/syntaxes/expressions/ExprWhitelist.sk @@ -15,4 +15,4 @@ test "enforce whitelist" when running minecraft "1.17": enforce whitelist assert server whitelist is enforced with "Failed to enforce server whitelist" unenforce whitelist - assert server whitelist is not enforced with "Failed to unenforce whitelist" \ No newline at end of file + assert server whitelist is not enforced with "Failed to unenforce whitelist"