-
-
Notifications
You must be signed in to change notification settings - Fork 1
Create Commands
Eric Lam edited this page Jun 13, 2022
·
5 revisions
Create A single Command is simple:
create a command:
@Commander(
name = "test",
description = "test command",
alias = {"tes", "te"}
)
public class TestCommand implements CommandNode {
@Override
public void execute(CommandSender commandSender) {
commandSender.sendMessage("test!");
}
}
public class TesterRegistry implements ComponentsRegistry {
@Override
public void registerCommand(CommandRegistry<CommandSender> commandRegistry) {
commandRegistry.command(TestCommand.class);
}
@Override
public void registerListeners(ListenerRegistry<Listener> listenerRegistry) {
}
}
root command
@Commander(
name = "test",
description = "test command",
alias = {"tes", "te"}
)
public class TestCommand implements CommandNode {
@Override
public void execute(CommandSender commandSender) {
}
}
subcommand 1
@Commander(
name = "one",
description = "test one command"
)
public class TestOneCommand implements CommandNode {
// here is the command arguments, which we will talk later
@CommandArg(order = 0, labels = {"string"})
private String value;
@Override
public void execute(CommandSender commandSender) {
commandSender.sendMessage("this is one command with value "+value);
}
}
subcommand 2
@Commander(
name = "two",
description = "two command"
)
public class TestTwoCommand implements CommandNode {
@CommandArg(order = 0)
private int number;
@Override
public void execute(CommandSender commandSender) {
commandSender.sendMessage("this is two command with number "+number);
}
}
and define their relationship:
public class TesterRegistry implements ComponentsRegistry {
@Override
public void registerCommand(CommandRegistry<CommandSender> commandRegistry) {
commandRegistry.command(TestCommand.class, c -> {
c.command(TestOneCommand.class);
c.command(TestTwoCommand.class);
});
}
@Override
public void registerListeners(ListenerRegistry<Listener> listenerRegistry) {
}
}