forked from chipmunkmc/chipmunkbot
Make Command
use LiteralCommandNode
s
This commit is contained in:
parent
eddbe38e0e
commit
5deddd71ab
5 changed files with 11 additions and 7 deletions
|
@ -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(); }
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public class HelpCommand extends Command {
|
|||
public HelpCommand () {
|
||||
super();
|
||||
|
||||
this.builder(
|
||||
this.node(
|
||||
literal("help")
|
||||
.executes(this::sendCommandList)
|
||||
);
|
||||
|
|
|
@ -13,7 +13,7 @@ public class RunCommand extends Command {
|
|||
public RunCommand () {
|
||||
super();
|
||||
|
||||
this.builder(
|
||||
this.node(
|
||||
literal("run")
|
||||
.then(
|
||||
argument("command", greedyString())
|
||||
|
|
|
@ -9,7 +9,7 @@ public class TestCommand extends Command {
|
|||
public TestCommand () {
|
||||
super();
|
||||
|
||||
this.builder(
|
||||
this.node(
|
||||
literal("test")
|
||||
.executes(this::helloWorld)
|
||||
);
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue