From f1c30b344fb3c916b7916883ce03ca11c979df1d Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 16 Jul 2023 18:46:07 +0700 Subject: [PATCH] some improvements about the cummand handler --- .../chayapak/chomens_bot/commands/HelpCommand.java | 5 +++-- .../chomens_bot/plugins/CommandHandlerPlugin.java | 12 +++++++----- .../chomens_bot/plugins/CommandSuggestionPlugin.java | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/HelpCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/HelpCommand.java index 48e2b49..217de9d 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/HelpCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/HelpCommand.java @@ -4,6 +4,7 @@ import land.chipmunk.chayapak.chomens_bot.Bot; import land.chipmunk.chayapak.chomens_bot.command.Command; import land.chipmunk.chayapak.chomens_bot.command.CommandContext; import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; +import land.chipmunk.chayapak.chomens_bot.plugins.CommandHandlerPlugin; import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.JoinConfiguration; @@ -66,7 +67,7 @@ public class HelpCommand extends Command { List commandNames = new ArrayList<>(); - for (Command command : bot.commandHandler.commands) { + for (Command command : CommandHandlerPlugin.commands) { if (command.trustLevel != trustLevel) continue; commandNames.add(command.name); @@ -103,7 +104,7 @@ public class HelpCommand extends Command { final String prefix = context.prefix; - for (Command command : bot.commandHandler.commands) { + for (Command command : CommandHandlerPlugin.commands) { if (!command.name.equals(args[0]) && !Arrays.stream(command.aliases).toList().contains(args[0])) continue; final String commandName = command.name; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java index 35414d4..4384851 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java @@ -20,13 +20,11 @@ import java.util.List; public class CommandHandlerPlugin { private final Bot bot; - public final List commands = new ArrayList<>(); + public static final List commands = new ArrayList<>(); public boolean disabled = false; - public CommandHandlerPlugin (Bot bot) { - this.bot = bot; - + static { registerCommand(new CommandBlockCommand()); registerCommand(new CowsayCommand()); registerCommand(new EchoCommand()); @@ -61,10 +59,14 @@ public class CommandHandlerPlugin { registerCommand(new InfoCommand()); } - public void registerCommand (Command command) { + public static void registerCommand (Command command) { commands.add(command); } + public CommandHandlerPlugin (Bot bot) { + this.bot = bot; + } + // literally the same quality as the js chomens bot // well probably less mess (mabe.,,.) public Component executeCommand ( diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSuggestionPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSuggestionPlugin.java index 19af098..f4913bd 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSuggestionPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSuggestionPlugin.java @@ -33,7 +33,7 @@ public class CommandSuggestionPlugin extends ChatPlugin.Listener { final List output = new ArrayList<>(); output.add(Component.text(id)); - for (Command command : bot.commandHandler.commands) { + for (Command command : CommandHandlerPlugin.commands) { output.add( Component .text(command.name)