From 36d88fdba8df1a46106c586a5deb0f6f7e9d96ef Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 8 Apr 2023 16:27:42 +0700 Subject: [PATCH] actually fix the console trusted thing --- .../chomens_bot/command/ConsoleCommandContext.java | 4 ++-- .../chomens_bot/plugins/ChatCommandHandlerPlugin.java | 2 +- .../chomens_bot/plugins/CommandHandlerPlugin.java | 8 ++++---- .../chayapak/chomens_bot/plugins/ConsolePlugin.java | 4 ++-- .../chayapak/chomens_bot/plugins/DiscordPlugin.java | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/command/ConsoleCommandContext.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/command/ConsoleCommandContext.java index 368e65f..78e0b11 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/command/ConsoleCommandContext.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/command/ConsoleCommandContext.java @@ -8,8 +8,8 @@ import net.kyori.adventure.text.format.NamedTextColor; public class ConsoleCommandContext extends CommandContext { private final Bot bot; - public ConsoleCommandContext (Bot bot, String prefix, String hash, String ownerHash) { - super(bot, prefix, bot.players().getEntry(bot.username()) /* real */, hash, ownerHash); + public ConsoleCommandContext (Bot bot, String prefix) { + super(bot, prefix, bot.players().getEntry(bot.username()) /* real */, null, null); this.bot = bot; } 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 20ede9e..bfcd335 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 @@ -55,7 +55,7 @@ public class ChatCommandHandlerPlugin extends ChatPlugin.ChatListener { final PlayerCommandContext context = new PlayerCommandContext(bot, displayName, prefix, selector, message.sender(), bot.hashing().hash(), bot.hashing().ownerHash()); - final Component output = bot.commandHandler().executeCommand(commandString, context, true, false, bot.hashing().hash(), bot.hashing().ownerHash(), null); + final Component output = bot.commandHandler().executeCommand(commandString, context, true, false, false, bot.hashing().hash(), bot.hashing().ownerHash(), null); final String textOutput = ((TextComponent) output).content(); if (!textOutput.equals("success")) { 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 aacac76..2a78e58 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 @@ -58,7 +58,7 @@ public class CommandHandlerPlugin { } // literally the same quality as the js chomens bot - public Component executeCommand (String input, CommandContext context, boolean inGame, boolean discord, String hash, String ownerHash, MessageReceivedEvent event) { + public Component executeCommand (String input, CommandContext context, boolean inGame, boolean discord, boolean console, String hash, String ownerHash, MessageReceivedEvent event) { final String[] splitInput = input.split("\\s+"); final String commandName = splitInput[0]; @@ -77,14 +77,14 @@ public class CommandHandlerPlugin { if (fullArgs.length < minimumArgs) return Component.text("Excepted minimum of " + minimumArgs + " argument(s), got " + fullArgs.length).color(NamedTextColor.RED); if (fullArgs.length > maximumArgs && !usage.contains("{")) return Component.text("Too much arguments, expected " + maximumArgs + " max").color(NamedTextColor.RED); - if (trustLevel > 0 && splitInput.length < 2) return Component.text("Please provide a hash").color(NamedTextColor.RED); + if (trustLevel > 0 && splitInput.length < 2 && !console) return Component.text("Please provide a hash").color(NamedTextColor.RED); String userHash = ""; - if (trustLevel > 0) userHash = splitInput[1]; + if (trustLevel > 0 && !console) userHash = splitInput[1]; final String[] args = Arrays.copyOfRange(splitInput, (trustLevel > 0 && inGame) ? 2 : 1, splitInput.length); - if (command.trustLevel() > 0) { + if (command.trustLevel() > 0 && !console) { if (discord) { final List roles = event.getMember().getRoles(); 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 cd0c22a..99d5b58 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 @@ -92,9 +92,9 @@ public class ConsolePlugin { if (!bot.host().equals(consoleServer) && !consoleServer.equals("all")) continue; if (line.startsWith(prefix)) { - final ConsoleCommandContext context = new ConsoleCommandContext(bot, prefix, "h", "o"); // ? should the hashes be hardcoded? + final ConsoleCommandContext context = new ConsoleCommandContext(bot, prefix); - final Component output = bot.commandHandler().executeCommand(line.substring(prefix.length()), context, false, false, "h", "o", null); + final Component output = bot.commandHandler().executeCommand(line.substring(prefix.length()), context, false, false, true, null, null, null); final String textOutput = ((TextComponent) output).content(); if (!textOutput.equals("success")) { 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 99deaa8..289ade7 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 @@ -78,7 +78,7 @@ public class DiscordPlugin { if (message.startsWith(prefix)) { final DiscordCommandContext context = new DiscordCommandContext(bot, prefix, event, null, null); - final Component output = bot.commandHandler().executeCommand(message.substring(prefix.length()), context, false, true, null, null, event); + final Component output = bot.commandHandler().executeCommand(message.substring(prefix.length()), context, false, true, false, null, null, event); final String textOutput = ((TextComponent) output).content(); if (!textOutput.equals("success")) {