From f038c4f54f9feaea066e52320896860d694d3b47 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 22 Jul 2023 16:25:43 +0700 Subject: [PATCH] better way to check for in game, discord and console --- .../chomens_bot/plugins/ChatCommandHandlerPlugin.java | 4 ++-- .../chomens_bot/plugins/CommandHandlerPlugin.java | 11 +++++------ .../chayapak/chomens_bot/plugins/ConsolePlugin.java | 2 +- .../chayapak/chomens_bot/plugins/DiscordPlugin.java | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatCommandHandlerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatCommandHandlerPlugin.java index 17c3320..9259a2e 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatCommandHandlerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatCommandHandlerPlugin.java @@ -58,7 +58,7 @@ public class ChatCommandHandlerPlugin extends ChatPlugin.Listener { final PlayerCommandContext context = new PlayerCommandContext(bot, displayName, prefix, "@a", message.sender); - final Component output = bot.commandHandler.executeCommand(commandString, context, true, false, false, null); + final Component output = bot.commandHandler.executeCommand(commandString, context, null); if (output != null) context.sendOutput(output); } @@ -90,7 +90,7 @@ public class ChatCommandHandlerPlugin extends ChatPlugin.Listener { final PlayerCommandContext context = new PlayerCommandContext(bot, displayName, prefix, selector, sender); - final Component output = bot.commandHandler.executeCommand(commandString, context, true, false, false, null); + final Component output = bot.commandHandler.executeCommand(commandString, context, null); if (output != null) context.sendOutput(output); } 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 2a0a93f..c3cd14e 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 @@ -1,9 +1,7 @@ package land.chipmunk.chayapak.chomens_bot.plugins; 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.command.*; import land.chipmunk.chayapak.chomens_bot.commands.*; import land.chipmunk.chayapak.chomens_bot.util.ExceptionUtilities; import net.dv8tion.jda.api.entities.Member; @@ -73,13 +71,14 @@ public class CommandHandlerPlugin { public Component executeCommand ( String input, CommandContext context, - boolean inGame, - boolean discord, - boolean console, MessageReceivedEvent event ) { if (disabled) return null; + final boolean inGame = context instanceof PlayerCommandContext; + final boolean discord = context instanceof DiscordCommandContext; + final boolean console = context instanceof ConsoleCommandContext; + final String[] splitInput = input.trim().split("\\s+"); final String commandName = splitInput[0]; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ConsolePlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ConsolePlugin.java index 515ff18..f282a40 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ConsolePlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ConsolePlugin.java @@ -70,7 +70,7 @@ public class ConsolePlugin { if (line.startsWith(prefix)) { final ConsoleCommandContext context = new ConsoleCommandContext(bot, prefix); - final Component output = bot.commandHandler.executeCommand(line.substring(prefix.length()), context, false, false, true, null); + final Component output = bot.commandHandler.executeCommand(line.substring(prefix.length()), context, null); if (output != null) { context.sendOutput(output); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java index bdb3a9d..20d4a43 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java @@ -133,7 +133,7 @@ public class DiscordPlugin { if (message.startsWith(prefix)) { final DiscordCommandContext context = new DiscordCommandContext(bot, prefix, event); - final Component output = bot.commandHandler.executeCommand(message.substring(prefix.length()), context, false, true, false, event); + final Component output = bot.commandHandler.executeCommand(message.substring(prefix.length()), context, event); if (output != null) { context.sendOutput(output);