Commands can be declared using the @Command annotation on a class:
@Command("foo")publicclassFoo {}
@Command("foo")classFoo
Subcommands
You can add a subcommand to a command by annotating a public method with @Command. The annotated method will be invoked whenever the specified subcommand is executed.
Command executors are simply something that can execute a command. You can obtain it by adding a CommandExecutor parameter to any subcommand or default command. Some platforms such as Paper provide their own additional command executor's like org.bukkit.command.CommandSender.
@Command("foo")publicclassFoo {// (Paper) anyone can execute /foo bar @Command("bar")publicvoidbar(CommandSender sender) {}// (Paper) only players can execute /foo baz @Command("baz")publicvoidbaz(Player sender) {}// Anyone can execute this /foo qux, reguardless of implementation or platform @Command("qux")publicvoidqux(CommandExecutor sender) {}}
@Command("foo")classFoo {// (Paper) anyone can execute /foo bar@Command("bar")funbar(sender: org.bukkit.command.CommandSender) {}// (Paper) only players can execute /foo baz@Command("baz")funbaz(sender: org.bukkit.entity.Player) {}// Anyone can execute this /foo qux, regardless of implementation or platform@Command("qux")funqux(sender: net.jailgens.enchanted.CommandExecutor) {}}
As shown in previous sections, if no command executor is specified, the subcommand or default command can be executed by any CommandExecutor.
Arguments
Command arguments are really easy to define. Simply append a parameter to the end of your command method: