From 2a9c2871b4b6d938f921a925f082ea31a2a1f3b8 Mon Sep 17 00:00:00 2001 From: wdog5 Date: Wed, 16 Oct 2024 09:53:19 +0800 Subject: [PATCH] Fixed #279 --- .../InjectionServerGamePacketListenerImpl.java | 4 ++++ .../MixinServerGamePacketListenerImpl.java | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/banner-server/src/main/java/com/mohistmc/banner/injection/server/network/InjectionServerGamePacketListenerImpl.java b/banner-server/src/main/java/com/mohistmc/banner/injection/server/network/InjectionServerGamePacketListenerImpl.java index 5a2409113..e6f1fbac6 100644 --- a/banner-server/src/main/java/com/mohistmc/banner/injection/server/network/InjectionServerGamePacketListenerImpl.java +++ b/banner-server/src/main/java/com/mohistmc/banner/injection/server/network/InjectionServerGamePacketListenerImpl.java @@ -67,4 +67,8 @@ default void pushTeleportCause(PlayerTeleportEvent.TeleportCause cause) { default boolean bridge$teleportCancelled() { throw new IllegalStateException("Not implemented"); } + + default void detectRateSpam(String s) { + throw new IllegalStateException("Not implemented"); + } } diff --git a/banner-server/src/main/java/com/mohistmc/banner/mixin/server/network/MixinServerGamePacketListenerImpl.java b/banner-server/src/main/java/com/mohistmc/banner/mixin/server/network/MixinServerGamePacketListenerImpl.java index ae4daa8de..6a32504c5 100644 --- a/banner-server/src/main/java/com/mohistmc/banner/mixin/server/network/MixinServerGamePacketListenerImpl.java +++ b/banner-server/src/main/java/com/mohistmc/banner/mixin/server/network/MixinServerGamePacketListenerImpl.java @@ -1223,7 +1223,23 @@ private void broadcastChatMessage(PlayerChatMessage playerchatmessage) { this.chat(s, playerchatmessage, true); } // this.server.getPlayerList().broadcastChatMessage(playerchatmessage, this.player, ChatMessageType.bind(ChatMessageType.CHAT, (Entity) this.player)); - this.detectRateSpam(); + this.detectRateSpam(s); + } + + @Override + public void detectRateSpam(String s) { + boolean counted = true; + for (String exclude : org.spigotmc.SpigotConfig.spamExclusions) { + if (exclude != null && s.startsWith(exclude)) { + counted = false; + break; + } + } + // Spigot end + this.chatSpamTickCount += 20; + if (counted && this.chatSpamTickCount > 200 && !this.server.getPlayerList().isOp(this.player.getGameProfile())) { + this.disconnect(Component.translatable("disconnect.spam")); + } } @Inject(method = "handlePlayerCommand", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;resetLastActionTime()V"))