From 9e529b2cefeca5ad6ad59658244b9658cfce1557 Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Sun, 27 Aug 2023 19:32:49 -0700 Subject: [PATCH 01/10] ExprSentCommands and EvtPlayerCommandSend --- .../skript/events/EvtPlayerCommandSend.java | 79 +++++++++ .../skript/expressions/ExprSentCommands.java | 152 ++++++++++++++++++ 2 files changed, 231 insertions(+) create mode 100644 src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java create mode 100644 src/main/java/ch/njol/skript/expressions/ExprSentCommands.java diff --git a/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java b/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java new file mode 100644 index 00000000000..89cd3034468 --- /dev/null +++ b/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java @@ -0,0 +1,79 @@ +/** + * 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.events; + +import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.lang.Literal; +import ch.njol.skript.lang.SkriptEvent; +import ch.njol.skript.lang.SkriptParser; +import com.google.common.collect.ImmutableCollection; +import com.google.common.collect.ImmutableList; +import org.bukkit.event.Event; +import org.bukkit.event.player.PlayerCommandSendEvent; +import org.eclipse.jdt.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Collection; + +@Name("Send Commands to Player") +@Description({ + "Called when the server sends a list of commands to the player. The sent commands can be modified via XYZ.", + "Modifications will affect what commands show up for the player to tab complete. They will not affect what commands the player can actually run.", + "Adding new commands to the list is illegal behavior and will be ignored." +}) +@Examples({ + "on send commands to player:", + "\tset sent commands to sent commands where [input does not contain \":\"]", + "\tadd \"fly\" to sent commands" +}) +@Since("INSERT VERSION") +public class EvtPlayerCommandSend extends SkriptEvent { + + static { + Skript.registerEvent("Send Commands to Player", EvtPlayerCommandSend.class, PlayerCommandSendEvent.class, "send[ing] commands to player"); + } + + Collection originalCommands = new ArrayList<>(); + + @Override + public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { + return true; + } + + @Override + public boolean check(Event event) { + originalCommands.clear(); + originalCommands.addAll(((PlayerCommandSendEvent) event).getCommands()); + return true; + } + + public ImmutableCollection getOriginalCommands() { + return ImmutableList.copyOf(originalCommands); + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "send commands to player"; + } + +} diff --git a/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java new file mode 100644 index 00000000000..60778b433d2 --- /dev/null +++ b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java @@ -0,0 +1,152 @@ +/** + * 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.expressions; + +import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Events; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.events.EvtPlayerCommandSend; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.ExpressionType; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.lang.util.SimpleExpression; +import ch.njol.util.Kleenean; +import org.bukkit.event.Event; +import org.bukkit.event.player.PlayerCommandSendEvent; +import org.eclipse.jdt.annotation.Nullable; +import org.skriptlang.skript.lang.structure.Structure; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +@Name("Sent Commands") +@Description({ + "The commands that will be sent to the player in a XYZ event.", + "Modifications will affect what commands show up for the player to tab complete. They will not affect what commands the player can actually run.", + "Adding new commands to the list is illegal behavior and will be ignored." +}) +@Examples({ + "on send commands to player:", + "\tset sent commands to sent commands where [input does not contain \":\"]", + "\tadd \"fly\" to sent commands" +}) +@Since("INSERT VERSION") +@Events("send commands to player") +public class ExprSentCommands extends SimpleExpression { + + static { + Skript.registerExpression(ExprSentCommands.class, String.class, ExpressionType.SIMPLE, "[the] sent commands"); + } + + private EvtPlayerCommandSend parent; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + if (!getParser().isCurrentEvent(PlayerCommandSendEvent.class)) + return false; + Structure structure = getParser().getCurrentStructure(); + if (!(structure instanceof EvtPlayerCommandSend)) + return false; + parent = (EvtPlayerCommandSend) structure; + return true; + } + + @Override + @Nullable + protected String[] get(Event event) { + if (!(event instanceof PlayerCommandSendEvent)) + return null; + return ((PlayerCommandSendEvent) event).getCommands().toArray(new String[0]); + } + + @Override + @Nullable + public Class[] acceptChange(ChangeMode mode) { + switch (mode) { + case REMOVE: + case REMOVE_ALL: + case DELETE: + case SET: + case RESET: + return new Class[]{String[].class}; + case ADD: + default: + return null; + } + } + + @Override + public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { + if (!(event instanceof PlayerCommandSendEvent)) + return; + + Collection commands = ((PlayerCommandSendEvent) event).getCommands(); + + // short circuit if we're just clearing the list + if (mode == ChangeMode.DELETE || mode == ChangeMode.REMOVE_ALL) { + commands.clear(); + return; + } + + List deltaCommands = (delta != null && delta.length > 0) ? new ArrayList<>(Arrays.asList((String[]) delta)) : new ArrayList<>(); + switch (mode) { + case REMOVE: + commands.removeAll(deltaCommands); + break; + case SET: + // remove all completely new commands, as adding new commands to the commands collection is illegal behaviour + List newCommands = new ArrayList<>(deltaCommands); + newCommands.removeAll(parent.getOriginalCommands()); + deltaCommands.removeAll(newCommands); + commands.clear(); + commands.addAll(deltaCommands); + break; + case RESET: + commands.clear(); + commands.addAll(parent.getOriginalCommands()); + break; + case ADD: + default: + assert false; + break; + } + } + + @Override + public boolean isSingle() { + return false; + } + + @Override + public Class getReturnType() { + return String.class; + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "the sent commands"; + } + +} From 54c6b6bde6c16feb26df4b488dbea866c0e2349d Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Sun, 27 Aug 2023 19:42:08 -0700 Subject: [PATCH 02/10] add links --- src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java | 2 +- src/main/java/ch/njol/skript/expressions/ExprSentCommands.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java b/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java index 89cd3034468..10ec98b8f39 100644 --- a/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java +++ b/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java @@ -37,7 +37,7 @@ @Name("Send Commands to Player") @Description({ - "Called when the server sends a list of commands to the player. The sent commands can be modified via XYZ.", + "Called when the server sends a list of commands to the player. The sent commands can be modified via the sent commands expression.", "Modifications will affect what commands show up for the player to tab complete. They will not affect what commands the player can actually run.", "Adding new commands to the list is illegal behavior and will be ignored." }) diff --git a/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java index 60778b433d2..b7552531d4b 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java +++ b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java @@ -43,7 +43,7 @@ @Name("Sent Commands") @Description({ - "The commands that will be sent to the player in a XYZ event.", + "The commands that will be sent to the player in a send commands to player event.", "Modifications will affect what commands show up for the player to tab complete. They will not affect what commands the player can actually run.", "Adding new commands to the list is illegal behavior and will be ignored." }) From 708a863a7eb4f0498bbfa09fde6c20bfb74a408d Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Mon, 28 Aug 2023 10:41:55 -0700 Subject: [PATCH 03/10] Requested Changes and Prevent Delayed Changes --- .../skript/events/EvtPlayerCommandSend.java | 36 +++++++++---------- .../skript/expressions/ExprSentCommands.java | 20 +++++++---- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java b/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java index 10ec98b8f39..ac8ac75bd55 100644 --- a/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java +++ b/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java @@ -19,13 +19,9 @@ package ch.njol.skript.events; import ch.njol.skript.Skript; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; -import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.lang.SkriptParser.ParseResult; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; import org.bukkit.event.Event; @@ -35,28 +31,28 @@ import java.util.ArrayList; import java.util.Collection; -@Name("Send Commands to Player") -@Description({ - "Called when the server sends a list of commands to the player. The sent commands can be modified via the sent commands expression.", - "Modifications will affect what commands show up for the player to tab complete. They will not affect what commands the player can actually run.", - "Adding new commands to the list is illegal behavior and will be ignored." -}) -@Examples({ - "on send commands to player:", - "\tset sent commands to sent commands where [input does not contain \":\"]", - "\tadd \"fly\" to sent commands" -}) -@Since("INSERT VERSION") public class EvtPlayerCommandSend extends SkriptEvent { static { - Skript.registerEvent("Send Commands to Player", EvtPlayerCommandSend.class, PlayerCommandSendEvent.class, "send[ing] commands to player"); + Skript.registerEvent("Send Command List", EvtPlayerCommandSend.class, PlayerCommandSendEvent.class, "send[ing] [of] [server] command[s] list ") + .description( + "Called when the server sends a list of commands to the player. This usually happens on join. The sent commands " + + "can be modified via the sent commands expression.", + "Modifications will affect what commands show up for the player to tab complete. They will not affect what commands the player can actually run.", + "Adding new commands to the list is illegal behavior and will be ignored." + ) + .examples( + "on send command list:", + "\tset command list to command list where [input does not contain \":\"]", + "\tremove \"help\" from command list" + ) + .since("INSERT VERSION"); } Collection originalCommands = new ArrayList<>(); @Override - public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { + public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { return true; } @@ -73,7 +69,7 @@ public ImmutableCollection getOriginalCommands() { @Override public String toString(@Nullable Event event, boolean debug) { - return "send commands to player"; + return "send server command list"; } } diff --git a/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java index b7552531d4b..e9e0e34867b 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java +++ b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java @@ -43,24 +43,25 @@ @Name("Sent Commands") @Description({ - "The commands that will be sent to the player in a send commands to player event.", + "The commands that will be sent to the player in a send commands to player event.", "Modifications will affect what commands show up for the player to tab complete. They will not affect what commands the player can actually run.", "Adding new commands to the list is illegal behavior and will be ignored." }) @Examples({ - "on send commands to player:", - "\tset sent commands to sent commands where [input does not contain \":\"]", - "\tadd \"fly\" to sent commands" + "on send command list:", + "\tset command list to command list where [input does not contain \":\"]", + "\tremove \"help\" from command list" }) @Since("INSERT VERSION") -@Events("send commands to player") +@Events("send command list") public class ExprSentCommands extends SimpleExpression { static { - Skript.registerExpression(ExprSentCommands.class, String.class, ExpressionType.SIMPLE, "[the] sent commands"); + Skript.registerExpression(ExprSentCommands.class, String.class, ExpressionType.SIMPLE, "[the] [sent] [server] command[s] list"); } private EvtPlayerCommandSend parent; + private Kleenean delay; @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { @@ -69,6 +70,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye Structure structure = getParser().getCurrentStructure(); if (!(structure instanceof EvtPlayerCommandSend)) return false; + delay = isDelayed; parent = (EvtPlayerCommandSend) structure; return true; } @@ -76,6 +78,10 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override @Nullable protected String[] get(Event event) { + if (delay != Kleenean.FALSE) { + Skript.error("Can't change the command list after the event has already passed"); + return null; + } if (!(event instanceof PlayerCommandSendEvent)) return null; return ((PlayerCommandSendEvent) event).getCommands().toArray(new String[0]); @@ -146,7 +152,7 @@ public Class getReturnType() { @Override public String toString(@Nullable Event event, boolean debug) { - return "the sent commands"; + return "the sent server command list"; } } From 5060b9ad544d1043ba126c6fcce9a56ca7451e2b Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Tue, 29 Aug 2023 09:09:28 -0700 Subject: [PATCH 04/10] Apply suggestions from code review Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com> --- src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java b/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java index ac8ac75bd55..91b7d6fb5b4 100644 --- a/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java +++ b/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java @@ -34,7 +34,7 @@ public class EvtPlayerCommandSend extends SkriptEvent { static { - Skript.registerEvent("Send Command List", EvtPlayerCommandSend.class, PlayerCommandSendEvent.class, "send[ing] [of] [server] command[s] list ") + Skript.registerEvent("Send Command List", EvtPlayerCommandSend.class, PlayerCommandSendEvent.class, "send[ing] [of] [server] command[s] list") .description( "Called when the server sends a list of commands to the player. This usually happens on join. The sent commands " + "can be modified via the sent commands expression.", From 089442c7f4035c3cf7e973a02d57523b64c4dc87 Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Tue, 29 Aug 2023 18:44:16 -0700 Subject: [PATCH 05/10] Suggestions --- .../java/ch/njol/skript/events/EvtPlayerCommandSend.java | 2 +- .../java/ch/njol/skript/expressions/ExprSentCommands.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java b/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java index ac8ac75bd55..a45605cdb7f 100644 --- a/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java +++ b/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java @@ -49,7 +49,7 @@ public class EvtPlayerCommandSend extends SkriptEvent { .since("INSERT VERSION"); } - Collection originalCommands = new ArrayList<>(); + private final Collection originalCommands = new ArrayList<>(); @Override public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { diff --git a/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java index e9e0e34867b..a05b73de7c9 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java +++ b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java @@ -41,7 +41,7 @@ import java.util.Collection; import java.util.List; -@Name("Sent Commands") +@Name("Sent Command List") @Description({ "The commands that will be sent to the player in a send commands to player event.", "Modifications will affect what commands show up for the player to tab complete. They will not affect what commands the player can actually run.", @@ -82,8 +82,10 @@ protected String[] get(Event event) { Skript.error("Can't change the command list after the event has already passed"); return null; } - if (!(event instanceof PlayerCommandSendEvent)) + if (!(event instanceof PlayerCommandSendEvent)) { + Skript.error("The 'command list' expression can only be used in a 'send command list' event"); return null; + } return ((PlayerCommandSendEvent) event).getCommands().toArray(new String[0]); } From 30be404dd8585ca165426a2b2049f9bb41a9a301 Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Mon, 25 Sep 2023 22:47:19 -0700 Subject: [PATCH 06/10] Requested Changes --- .../skript/expressions/ExprSentCommands.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java index a05b73de7c9..647f595af6d 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java +++ b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java @@ -31,13 +31,13 @@ import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; +import com.google.common.collect.Lists; import org.bukkit.event.Event; import org.bukkit.event.player.PlayerCommandSendEvent; import org.eclipse.jdt.annotation.Nullable; import org.skriptlang.skript.lang.structure.Structure; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -61,16 +61,24 @@ public class ExprSentCommands extends SimpleExpression { } private EvtPlayerCommandSend parent; - private Kleenean delay; @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - if (!getParser().isCurrentEvent(PlayerCommandSendEvent.class)) + public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + if (!getParser().isCurrentEvent(PlayerCommandSendEvent.class)) { + Skript.error("The 'command list' expression can only be used in a 'send command list' event"); return false; + } + Structure structure = getParser().getCurrentStructure(); - if (!(structure instanceof EvtPlayerCommandSend)) + if (!(structure instanceof EvtPlayerCommandSend)) { + Skript.error("The 'command list' expression can only be used in a 'send command list' event"); + return false; + } + + if (isDelayed.isFalse()) { + Skript.error("Can't change the command list after the event has already passed"); return false; - delay = isDelayed; + } parent = (EvtPlayerCommandSend) structure; return true; } @@ -78,14 +86,8 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override @Nullable protected String[] get(Event event) { - if (delay != Kleenean.FALSE) { - Skript.error("Can't change the command list after the event has already passed"); - return null; - } - if (!(event instanceof PlayerCommandSendEvent)) { - Skript.error("The 'command list' expression can only be used in a 'send command list' event"); + if (!(event instanceof PlayerCommandSendEvent)) return null; - } return ((PlayerCommandSendEvent) event).getCommands().toArray(new String[0]); } @@ -118,7 +120,7 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { return; } - List deltaCommands = (delta != null && delta.length > 0) ? new ArrayList<>(Arrays.asList((String[]) delta)) : new ArrayList<>(); + List deltaCommands = (delta != null && delta.length > 0) ? Lists.newArrayList((String[]) delta) : new ArrayList<>(); switch (mode) { case REMOVE: commands.removeAll(deltaCommands); @@ -154,7 +156,7 @@ public Class getReturnType() { @Override public String toString(@Nullable Event event, boolean debug) { - return "the sent server command list"; + return "sent server command list"; } } From aaecd2c1db6f8ba6bb8d06badec953d27189b294 Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Mon, 25 Sep 2023 23:17:24 -0700 Subject: [PATCH 07/10] silly mistake --- src/main/java/ch/njol/skript/expressions/ExprSentCommands.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java index 647f595af6d..421d67d7532 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java +++ b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java @@ -75,7 +75,7 @@ public boolean init(Expression[] expressions, int matchedPattern, Kleenean is return false; } - if (isDelayed.isFalse()) { + if (!isDelayed.isFalse()) { Skript.error("Can't change the command list after the event has already passed"); return false; } From 4cfa7562a8cfc82ea98d6d4bc421a59258a7d666 Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Sat, 16 Dec 2023 21:43:24 -0800 Subject: [PATCH 08/10] Requested Changes --- .../ch/njol/skript/events/EvtPlayerCommandSend.java | 2 +- .../ch/njol/skript/expressions/ExprSentCommands.java | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java b/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java index c7c4f636771..00681160224 100644 --- a/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java +++ b/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java @@ -34,7 +34,7 @@ public class EvtPlayerCommandSend extends SkriptEvent { static { - Skript.registerEvent("Send Command List", EvtPlayerCommandSend.class, PlayerCommandSendEvent.class, "send[ing] [of] [server] command[s] list") + Skript.registerEvent("Send Command List", EvtPlayerCommandSend.class, PlayerCommandSendEvent.class, "send[ing] [of] [the] [server] command[s] list", "[server] command list send") .description( "Called when the server sends a list of commands to the player. This usually happens on join. The sent commands " + "can be modified via the sent commands expression.", diff --git a/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java index 421d67d7532..6414c1d93ce 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java +++ b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java @@ -64,11 +64,6 @@ public class ExprSentCommands extends SimpleExpression { @Override public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - if (!getParser().isCurrentEvent(PlayerCommandSendEvent.class)) { - Skript.error("The 'command list' expression can only be used in a 'send command list' event"); - return false; - } - Structure structure = getParser().getCurrentStructure(); if (!(structure instanceof EvtPlayerCommandSend)) { Skript.error("The 'command list' expression can only be used in a 'send command list' event"); @@ -96,12 +91,11 @@ protected String[] get(Event event) { public Class[] acceptChange(ChangeMode mode) { switch (mode) { case REMOVE: - case REMOVE_ALL: case DELETE: case SET: case RESET: return new Class[]{String[].class}; - case ADD: + // note that ADD is not supported, as adding new commands to the commands collection is illegal behaviour default: return null; } @@ -156,7 +150,7 @@ public Class getReturnType() { @Override public String toString(@Nullable Event event, boolean debug) { - return "sent server command list"; + return "the sent server command list"; } } From 661a446eba858e5b41bc1a1e2a6cb539aedc6d1a Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Tue, 19 Dec 2023 14:01:04 -0800 Subject: [PATCH 09/10] Apply suggestions from code review Co-authored-by: Patrick Miller --- src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java | 4 ++-- .../java/ch/njol/skript/expressions/ExprSentCommands.java | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java b/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java index 00681160224..9ef380ada7a 100644 --- a/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java +++ b/src/main/java/ch/njol/skript/events/EvtPlayerCommandSend.java @@ -34,7 +34,7 @@ public class EvtPlayerCommandSend extends SkriptEvent { static { - Skript.registerEvent("Send Command List", EvtPlayerCommandSend.class, PlayerCommandSendEvent.class, "send[ing] [of] [the] [server] command[s] list", "[server] command list send") + Skript.registerEvent("Send Command List", EvtPlayerCommandSend.class, PlayerCommandSendEvent.class, "send[ing] [of [the]] [server] command[s] list", "[server] command list send") .description( "Called when the server sends a list of commands to the player. This usually happens on join. The sent commands " + "can be modified via the sent commands expression.", @@ -69,7 +69,7 @@ public ImmutableCollection getOriginalCommands() { @Override public String toString(@Nullable Event event, boolean debug) { - return "send server command list"; + return "sending of the server command list"; } } diff --git a/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java index 6414c1d93ce..4241a36e6d8 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java +++ b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java @@ -131,7 +131,6 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { commands.clear(); commands.addAll(parent.getOriginalCommands()); break; - case ADD: default: assert false; break; From 093e4c8c33efc97d24a8d19c6a7cce71df4078bc Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Sun, 31 Dec 2023 18:13:05 -0800 Subject: [PATCH 10/10] Update ExprSentCommands.java --- src/main/java/ch/njol/skript/expressions/ExprSentCommands.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java index 4241a36e6d8..5c4f17ab16e 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java +++ b/src/main/java/ch/njol/skript/expressions/ExprSentCommands.java @@ -109,7 +109,7 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { Collection commands = ((PlayerCommandSendEvent) event).getCommands(); // short circuit if we're just clearing the list - if (mode == ChangeMode.DELETE || mode == ChangeMode.REMOVE_ALL) { + if (mode == ChangeMode.DELETE) { commands.clear(); return; }