From 7450b8bcc9c2da492890ddc46d23b64cb0a3588b Mon Sep 17 00:00:00 2001 From: amy <144570677+amyavi@users.noreply.github.com> Date: Tue, 10 Sep 2024 20:15:45 -0300 Subject: [PATCH] Don't re-apply command rate-limit when command is ratelimited (#364) * fix: don't re-apply ratelimit when user is already ratelimited * fix: lower command ratelimit event priority Makes command spam not show up in CommandSpy --- .../java/pw/kaboom/extras/modules/player/PlayerChat.java | 3 ++- .../pw/kaboom/extras/modules/player/PlayerCommand.java | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java index 62747cb..a40644e 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java @@ -23,7 +23,7 @@ import java.util.regex.Pattern; public final class PlayerChat implements Listener { private static final PlayerChatRenderer CHAT_RENDERER = new PlayerChatRenderer(); - @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler(ignoreCancelled = true, priority = EventPriority.LOW) void onAsyncChatEventProcess(final AsyncChatEvent event) { final UUID playerUuid = event.getPlayer().getUniqueId(); @@ -33,6 +33,7 @@ public final class PlayerChat implements Listener { if (millisDifference < 50) { event.setCancelled(true); + return; } } diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerCommand.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerCommand.java index b1fd441..cc3e5d0 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerCommand.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerCommand.java @@ -6,6 +6,7 @@ import java.util.UUID; import io.papermc.paper.event.player.PlayerSignCommandPreprocessEvent; import org.bukkit.command.CommandSender; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerCommandPreprocessEvent; @@ -14,7 +15,7 @@ import pw.kaboom.extras.modules.server.ServerCommand; public final class PlayerCommand implements Listener { private static HashMap commandMillisList = new HashMap(); - @EventHandler + @EventHandler(ignoreCancelled = true, priority = EventPriority.LOW) void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) { final UUID playerUuid = event.getPlayer().getUniqueId(); @@ -24,15 +25,12 @@ public final class PlayerCommand implements Listener { if (millisDifference < 75) { event.setCancelled(true); + return; } } getCommandMillisList().put(playerUuid, System.currentTimeMillis()); - if (event.isCancelled()) { - return; - } - final CommandSender sender = event.getPlayer(); final String command = event.getMessage(); final boolean isConsoleCommand = false;