From 379303ba69e454a818e4346856a83f48759f15ea Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Mon, 27 Mar 2023 11:04:28 +0700 Subject: [PATCH] =?UTF-8?q?anti=20clearchat=20totallynotskidded=E2=84=A2?= =?UTF-8?q?=20idea=20from=20chipmunkbot=20js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/me/chayapak1/chomens_bot/Bot.java | 2 + .../plugins/AntiClearChatPlugin.java | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/main/java/me/chayapak1/chomens_bot/plugins/AntiClearChatPlugin.java diff --git a/src/main/java/me/chayapak1/chomens_bot/Bot.java b/src/main/java/me/chayapak1/chomens_bot/Bot.java index 629c1d3..e265629 100644 --- a/src/main/java/me/chayapak1/chomens_bot/Bot.java +++ b/src/main/java/me/chayapak1/chomens_bot/Bot.java @@ -44,6 +44,7 @@ public class Bot { @Getter private final MusicPlayerPlugin music; @Getter private final TPSPlugin tps; @Getter private final EvalRunnerPlugin eval; + @Getter private final AntiClearChatPlugin antiClearChat; public Bot (String host, int port, String _username, boolean kaboom, List allBots, Configuration config) { this.host = host; @@ -69,6 +70,7 @@ public class Bot { this.music = new MusicPlayerPlugin(this); this.tps = new TPSPlugin(this); this.eval = new EvalRunnerPlugin(this); + this.antiClearChat = new AntiClearChatPlugin(this); reconnect(); } diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/AntiClearChatPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/AntiClearChatPlugin.java new file mode 100644 index 0000000..b76db29 --- /dev/null +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/AntiClearChatPlugin.java @@ -0,0 +1,38 @@ +package me.chayapak1.chomens_bot.plugins; + +import me.chayapak1.chomens_bot.Bot; +import me.chayapak1.chomens_bot.chatParsers.data.PlayerMessage; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.format.NamedTextColor; + +// idea totallynotskidded™ from chipmunkbot (the js one) +public class AntiClearChatPlugin extends ChatPlugin.ChatListener { + private final Bot bot; + + public AntiClearChatPlugin (Bot bot) { + this.bot = bot; + + bot.chat().addListener(this); + } + + @Override + public void commandSpyMessageReceived (PlayerMessage message) { + final String username = message.sender().profile().getName(); + final String command = ((TextComponent) message.parameters().get("contents")).content(); + + if ( + command.equals("/clearchat") || + command.equals("/cc") || + command.equals("/extras:clearchat") || + command.equals("/extras:cc") + ) { + bot.chat().tellraw( + Component.empty() + .append(Component.text(username)) + .append(Component.text(" cleared the chat")) + .color(NamedTextColor.DARK_GREEN) + ); + } + } +}