From 14b2b5368239fbc87473571060109b90efabed28 Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Sat, 25 Mar 2023 14:59:48 +0700 Subject: [PATCH] add clearchat --- .../commands/ClearChatCommand.java | 70 +++++++++++++++++++ .../plugins/CommandHandlerPlugin.java | 1 + 2 files changed, 71 insertions(+) create mode 100644 src/main/java/me/chayapak1/chomens_bot/commands/ClearChatCommand.java diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/ClearChatCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/ClearChatCommand.java new file mode 100644 index 0000000..3f42293 --- /dev/null +++ b/src/main/java/me/chayapak1/chomens_bot/commands/ClearChatCommand.java @@ -0,0 +1,70 @@ +package me.chayapak1.chomens_bot.commands; + +import me.chayapak1.chomens_bot.Bot; +import me.chayapak1.chomens_bot.chatParsers.data.MutablePlayerListEntry; +import me.chayapak1.chomens_bot.command.Command; +import me.chayapak1.chomens_bot.command.CommandContext; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class ClearChatCommand implements Command { + public String name() { return "clearchat"; } + + public String description() { + return "Clears the chat"; + } + + public List usage() { + final List usages = new ArrayList<>(); + usages.add("[player]"); + + return usages; + } + + public List alias() { + final List aliases = new ArrayList<>(); + aliases.add("cc"); + + return aliases; + } + + public int trustLevel() { + return 0; + } + + public Component execute(CommandContext context, String[] args, String[] fullArgs) { + final Bot bot = context.bot(); + + if (args.length > 0) { + final MutablePlayerListEntry entry = bot.players().getEntry(String.join(" ", args)); + + if (entry == null) return Component.text("Invalid player name").color(NamedTextColor.RED); + + final UUID uuid = entry.profile().getId(); + + bot.chat().tellraw( + Component.empty() + .append(Component.text("\n".repeat(1000))) + .append( + Component.empty() + .append(Component.text("Your chat has been cleared by ")) + .append(context.displayName()) + .color(NamedTextColor.DARK_GREEN) + ), + uuid + ); + } else { + bot.chat().tellraw( + Component.empty() + .append(Component.text("\n".repeat(1000))) + .append(Component.text("The chat has been cleared").color(NamedTextColor.DARK_GREEN)) + ); + } + + return Component.text("success"); + } +} diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/CommandHandlerPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/CommandHandlerPlugin.java index b1d9bce..6c9f2b8 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/CommandHandlerPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/CommandHandlerPlugin.java @@ -35,6 +35,7 @@ public class CommandHandlerPlugin { registerCommand(new RefillCoreCommand()); registerCommand(new WikipediaCommand()); registerCommand(new UrbanCommand()); + registerCommand(new ClearChatCommand()); } public void registerCommand (Command command) {