refactor: change command handler executeCommand signature to be more clean

This commit is contained in:
ChomeNS
2025-04-14 09:07:41 +07:00
parent b7807686d0
commit 97152d7bd0
9 changed files with 20 additions and 11 deletions

View File

@@ -1 +1 @@
2684
2687

View File

@@ -58,6 +58,6 @@ public class PacketHandler {
player
);
bot.commandHandler.executeCommand(input, context, null);
bot.commandHandler.executeCommand(input, context);
}
}

View File

@@ -18,7 +18,7 @@ import java.awt.*;
import java.nio.charset.StandardCharsets;
public class DiscordCommandContext extends CommandContext {
private final MessageReceivedEvent event;
public final MessageReceivedEvent event;
private final Bot bot;

View File

@@ -61,7 +61,7 @@ public class NetCommandCommand extends Command {
final CommandContext remoteContext = new RemoteCommandContext(bot, context);
context.bot.commandHandler.executeCommand(command, remoteContext, null);
context.bot.commandHandler.executeCommand(command, remoteContext);
}
return null;

View File

@@ -61,7 +61,7 @@ public class GuildMessageEventHandler extends ListenerAdapter {
if (messageString.startsWith(prefix)) {
final DiscordCommandContext context = new DiscordCommandContext(bot, prefix, event);
bot.commandHandler.executeCommand(messageString.substring(prefix.length()), context, event);
bot.commandHandler.executeCommand(messageString.substring(prefix.length()), context);
return;
}

View File

@@ -98,6 +98,6 @@ public class ChatCommandHandlerPlugin implements ChatPlugin.Listener, CommandSpy
packetType
);
bot.commandHandler.executeCommand(commandString, context, null);
bot.commandHandler.executeCommand(commandString, context);
}
}

View File

@@ -108,11 +108,20 @@ public class CommandHandlerPlugin implements TickPlugin.Listener {
// though it can also be as low as 4000 ns)
public void executeCommand (
final String input,
final CommandContext context,
final MessageReceivedEvent event
final CommandContext context
) {
final boolean inGame = context instanceof PlayerCommandContext;
final boolean discord = context instanceof DiscordCommandContext;
final boolean discord;
final MessageReceivedEvent event;
if (context instanceof final DiscordCommandContext discordContext) {
discord = true;
event = discordContext.event;
} else {
discord = false;
event = null;
}
final boolean bypass = context instanceof ConsoleCommandContext || context instanceof ChomeNSModCommandContext;

View File

@@ -95,7 +95,7 @@ public class ConsolePlugin implements Completer {
if (line.startsWith(prefix)) {
final ConsoleCommandContext context = new ConsoleCommandContext(bot, prefix);
bot.commandHandler.executeCommand(line.substring(prefix.length()), context, null);
bot.commandHandler.executeCommand(line.substring(prefix.length()), context);
continue;
}

View File

@@ -123,7 +123,7 @@ public class IRCPlugin extends ListenerAdapter {
final IRCCommandContext context = new IRCCommandContext(serverBot, commandPrefix, name);
serverBot.commandHandler.executeCommand(noPrefix, context, null);
serverBot.commandHandler.executeCommand(noPrefix, context);
return;
}