some improvements about the cummand handler

This commit is contained in:
Chayapak 2023-07-16 18:46:07 +07:00
parent 324ae6a13f
commit f1c30b344f
3 changed files with 11 additions and 8 deletions

View file

@ -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.Command;
import land.chipmunk.chayapak.chomens_bot.command.CommandContext; import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; 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 land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration; import net.kyori.adventure.text.JoinConfiguration;
@ -66,7 +67,7 @@ public class HelpCommand extends Command {
List<String> commandNames = new ArrayList<>(); List<String> commandNames = new ArrayList<>();
for (Command command : bot.commandHandler.commands) { for (Command command : CommandHandlerPlugin.commands) {
if (command.trustLevel != trustLevel) continue; if (command.trustLevel != trustLevel) continue;
commandNames.add(command.name); commandNames.add(command.name);
@ -103,7 +104,7 @@ public class HelpCommand extends Command {
final String prefix = context.prefix; 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; if (!command.name.equals(args[0]) && !Arrays.stream(command.aliases).toList().contains(args[0])) continue;
final String commandName = command.name; final String commandName = command.name;

View file

@ -20,13 +20,11 @@ import java.util.List;
public class CommandHandlerPlugin { public class CommandHandlerPlugin {
private final Bot bot; private final Bot bot;
public final List<Command> commands = new ArrayList<>(); public static final List<Command> commands = new ArrayList<>();
public boolean disabled = false; public boolean disabled = false;
public CommandHandlerPlugin (Bot bot) { static {
this.bot = bot;
registerCommand(new CommandBlockCommand()); registerCommand(new CommandBlockCommand());
registerCommand(new CowsayCommand()); registerCommand(new CowsayCommand());
registerCommand(new EchoCommand()); registerCommand(new EchoCommand());
@ -61,10 +59,14 @@ public class CommandHandlerPlugin {
registerCommand(new InfoCommand()); registerCommand(new InfoCommand());
} }
public void registerCommand (Command command) { public static void registerCommand (Command command) {
commands.add(command); commands.add(command);
} }
public CommandHandlerPlugin (Bot bot) {
this.bot = bot;
}
// literally the same quality as the js chomens bot // literally the same quality as the js chomens bot
// well probably less mess (mabe.,,.) // well probably less mess (mabe.,,.)
public Component executeCommand ( public Component executeCommand (

View file

@ -33,7 +33,7 @@ public class CommandSuggestionPlugin extends ChatPlugin.Listener {
final List<Component> output = new ArrayList<>(); final List<Component> output = new ArrayList<>();
output.add(Component.text(id)); output.add(Component.text(id));
for (Command command : bot.commandHandler.commands) { for (Command command : CommandHandlerPlugin.commands) {
output.add( output.add(
Component Component
.text(command.name) .text(command.name)