Make Command use LiteralCommandNodes

This commit is contained in:
Chipmunk 2023-01-19 18:16:39 -05:00
parent eddbe38e0e
commit 5deddd71ab
5 changed files with 11 additions and 7 deletions

View file

@ -1,13 +1,15 @@
package land.chipmunk.chipmunkbot.command;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import lombok.Data;
import lombok.Getter;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Command {
private LiteralArgumentBuilder<CommandSource> builder;
@Getter private LiteralCommandNode<CommandSource> node;
protected void node (LiteralCommandNode<CommandSource> node) { this.node = node; }
protected void node (LiteralArgumentBuilder<CommandSource> builder) { this.node = builder.build(); }
}

View file

@ -19,7 +19,7 @@ public class HelpCommand extends Command {
public HelpCommand () {
super();
this.builder(
this.node(
literal("help")
.executes(this::sendCommandList)
);

View file

@ -13,7 +13,7 @@ public class RunCommand extends Command {
public RunCommand () {
super();
this.builder(
this.node(
literal("run")
.then(
argument("command", greedyString())

View file

@ -9,7 +9,7 @@ public class TestCommand extends Command {
public TestCommand () {
super();
this.builder(
this.node(
literal("test")
.executes(this::helloWorld)
);

View file

@ -12,6 +12,7 @@ import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.event.ClickEvent;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.tree.RootCommandNode;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.Message;
@ -32,7 +33,8 @@ public class CommandManager {
public CommandManager (ChipmunkBot client) {
this.client = client;
for (Command command : commands) dispatcher.register(command.builder());
final RootCommandNode root = dispatcher.getRoot();
for (Command command : commands) root.addChild(command.node());
}
public static void sendException (CommandSource source, CommandSyntaxException exception) {