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
This commit is contained in:
amy 2024-09-10 20:15:45 -03:00 committed by GitHub
parent 8fe96bcc2b
commit 7450b8bcc9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 6 deletions

View file

@ -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;
}
}

View file

@ -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<UUID, Long> commandMillisList = new HashMap<UUID, Long>();
@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;