update test a bit
This commit is contained in:
parent
6156620a0c
commit
105802ef48
5 changed files with 22 additions and 14 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -17,7 +17,7 @@ public class TestCommand implements Command {
|
|||
|
||||
public List<String> usage() {
|
||||
final List<String> 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");
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue