forked from ChomeNS/chomens-bot-java
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 lombok.Getter;
|
||||||
import me.chayapak1.chomens_bot.Bot;
|
import me.chayapak1.chomens_bot.Bot;
|
||||||
|
import me.chayapak1.chomens_bot.chatParsers.data.MutablePlayerListEntry;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
||||||
public class CommandContext {
|
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 hash;
|
||||||
@Getter private final String ownerHash;
|
@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.bot = bot;
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
|
this.sender = sender;
|
||||||
this.hash = hash;
|
this.hash = hash;
|
||||||
this.ownerHash = ownerHash;
|
this.ownerHash = ownerHash;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ public class ConsoleCommandContext extends CommandContext {
|
||||||
private final Bot bot;
|
private final Bot bot;
|
||||||
|
|
||||||
public ConsoleCommandContext (Bot bot, String prefix, String hash, String ownerHash) {
|
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;
|
this.bot = bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package me.chayapak1.chomens_bot.command;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.chayapak1.chomens_bot.Bot;
|
import me.chayapak1.chomens_bot.Bot;
|
||||||
|
import me.chayapak1.chomens_bot.chatParsers.data.MutablePlayerListEntry;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
||||||
public class PlayerCommandContext extends CommandContext {
|
public class PlayerCommandContext extends CommandContext {
|
||||||
|
@ -11,8 +12,8 @@ public class PlayerCommandContext extends CommandContext {
|
||||||
|
|
||||||
private final Bot bot;
|
private final Bot bot;
|
||||||
|
|
||||||
public PlayerCommandContext (Bot bot, String playerName, String prefix, String selector, String hash, String ownerHash) {
|
public PlayerCommandContext (Bot bot, String playerName, String prefix, String selector, MutablePlayerListEntry sender, String hash, String ownerHash) {
|
||||||
super(bot, prefix, hash, ownerHash);
|
super(bot, prefix, sender, hash, ownerHash);
|
||||||
this.bot = bot;
|
this.bot = bot;
|
||||||
this.playerName = playerName;
|
this.playerName = playerName;
|
||||||
this.selector = selector;
|
this.selector = selector;
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class TestCommand implements Command {
|
||||||
|
|
||||||
public List<String> usage() {
|
public List<String> usage() {
|
||||||
final List<String> usages = new ArrayList<>();
|
final List<String> usages = new ArrayList<>();
|
||||||
usages.add("");
|
usages.add("[{args}]");
|
||||||
|
|
||||||
return usages;
|
return usages;
|
||||||
}
|
}
|
||||||
|
@ -34,12 +34,15 @@ public class TestCommand implements Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||||
context.sendOutput(
|
final Component component = Component.translatable(
|
||||||
Component.empty()
|
"Hello, World! Username: %s, Sender UUID: %s, Prefix: %s, Args: %s",
|
||||||
.append(Component.text("Hello, World! Username: "))
|
context.displayName(),
|
||||||
.append(context.displayName())
|
Component.text(context.sender().profile().getIdAsString()),
|
||||||
.color(NamedTextColor.GREEN)
|
Component.text(context.prefix()),
|
||||||
);
|
Component.text(String.join(", ", args))
|
||||||
|
).color(NamedTextColor.GREEN);
|
||||||
|
|
||||||
|
context.sendOutput(component);
|
||||||
|
|
||||||
return Component.text("success");
|
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 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 Component output = bot.commandHandler().executeCommand(commandString, context, bot.hashing().hash(), bot.hashing().ownerHash());
|
||||||
final String textOutput = ((TextComponent) output).content();
|
final String textOutput = ((TextComponent) output).content();
|
||||||
|
|
Loading…
Reference in a new issue