From 105802ef488642ee3017abe25dc3075b2cb959cc Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Sun, 26 Mar 2023 08:20:11 +0700 Subject: [PATCH] update test a bit --- .../chomens_bot/command/CommandContext.java | 10 +++++++--- .../command/ConsoleCommandContext.java | 2 +- .../command/PlayerCommandContext.java | 5 +++-- .../chomens_bot/commands/TestCommand.java | 17 ++++++++++------- .../plugins/ChatCommandHandlerPlugin.java | 2 +- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/chayapak1/chomens_bot/command/CommandContext.java b/src/main/java/me/chayapak1/chomens_bot/command/CommandContext.java index 251c48b..c910f93 100644 --- a/src/main/java/me/chayapak1/chomens_bot/command/CommandContext.java +++ b/src/main/java/me/chayapak1/chomens_bot/command/CommandContext.java @@ -2,19 +2,23 @@ package me.chayapak1.chomens_bot.command; import lombok.Getter; import me.chayapak1.chomens_bot.Bot; +import me.chayapak1.chomens_bot.chatParsers.data.MutablePlayerListEntry; import net.kyori.adventure.text.Component; public class CommandContext { - @Getter public final Bot bot; + @Getter private final Bot bot; - @Getter public final String prefix; + @Getter private final String prefix; + + @Getter private final MutablePlayerListEntry sender; @Getter private final String hash; @Getter private final String ownerHash; - public CommandContext(Bot bot, String prefix, String hash, String ownerHash) { + public CommandContext(Bot bot, String prefix, MutablePlayerListEntry sender, String hash, String ownerHash) { this.bot = bot; this.prefix = prefix; + this.sender = sender; this.hash = hash; this.ownerHash = ownerHash; } diff --git a/src/main/java/me/chayapak1/chomens_bot/command/ConsoleCommandContext.java b/src/main/java/me/chayapak1/chomens_bot/command/ConsoleCommandContext.java index d39a5c5..ef8112d 100644 --- a/src/main/java/me/chayapak1/chomens_bot/command/ConsoleCommandContext.java +++ b/src/main/java/me/chayapak1/chomens_bot/command/ConsoleCommandContext.java @@ -9,7 +9,7 @@ public class ConsoleCommandContext extends CommandContext { private final Bot bot; public ConsoleCommandContext (Bot bot, String prefix, String hash, String ownerHash) { - super(bot, prefix, hash, ownerHash); + super(bot, prefix, bot.players().getEntry(bot.username()) /* real */, hash, ownerHash); this.bot = bot; } diff --git a/src/main/java/me/chayapak1/chomens_bot/command/PlayerCommandContext.java b/src/main/java/me/chayapak1/chomens_bot/command/PlayerCommandContext.java index 6b3d2f6..115e997 100644 --- a/src/main/java/me/chayapak1/chomens_bot/command/PlayerCommandContext.java +++ b/src/main/java/me/chayapak1/chomens_bot/command/PlayerCommandContext.java @@ -2,6 +2,7 @@ package me.chayapak1.chomens_bot.command; import lombok.Getter; import me.chayapak1.chomens_bot.Bot; +import me.chayapak1.chomens_bot.chatParsers.data.MutablePlayerListEntry; import net.kyori.adventure.text.Component; public class PlayerCommandContext extends CommandContext { @@ -11,8 +12,8 @@ public class PlayerCommandContext extends CommandContext { private final Bot bot; - public PlayerCommandContext (Bot bot, String playerName, String prefix, String selector, String hash, String ownerHash) { - super(bot, prefix, hash, ownerHash); + public PlayerCommandContext (Bot bot, String playerName, String prefix, String selector, MutablePlayerListEntry sender, String hash, String ownerHash) { + super(bot, prefix, sender, hash, ownerHash); this.bot = bot; this.playerName = playerName; this.selector = selector; diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/TestCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/TestCommand.java index 549d4b2..1a33476 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/TestCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/TestCommand.java @@ -17,7 +17,7 @@ public class TestCommand implements Command { public List usage() { final List usages = new ArrayList<>(); - usages.add(""); + usages.add("[{args}]"); return usages; } @@ -34,12 +34,15 @@ public class TestCommand implements Command { } public Component execute(CommandContext context, String[] args, String[] fullArgs) { - context.sendOutput( - Component.empty() - .append(Component.text("Hello, World! Username: ")) - .append(context.displayName()) - .color(NamedTextColor.GREEN) - ); + final Component component = Component.translatable( + "Hello, World! Username: %s, Sender UUID: %s, Prefix: %s, Args: %s", + context.displayName(), + Component.text(context.sender().profile().getIdAsString()), + Component.text(context.prefix()), + Component.text(String.join(", ", args)) + ).color(NamedTextColor.GREEN); + + context.sendOutput(component); return Component.text("success"); } diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/ChatCommandHandlerPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/ChatCommandHandlerPlugin.java index 4423fea..3cdad7b 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/ChatCommandHandlerPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/ChatCommandHandlerPlugin.java @@ -53,7 +53,7 @@ public class ChatCommandHandlerPlugin extends ChatPlugin.ChatListener { final String selector = cspy ? UUIDUtilities.selector(message.sender().profile().getId()) : "@a"; - final PlayerCommandContext context = new PlayerCommandContext(bot, displayName, prefix, selector, bot.hashing().hash(), bot.hashing().ownerHash()); + 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, bot.hashing().hash(), bot.hashing().ownerHash()); final String textOutput = ((TextComponent) output).content();