Commands
Commands are the main communication between the server and the players. In contrary to current alternatives, Minestom takes full advantage of auto-completion/suggestion and has therefore a fairly strict API.
All auto-completable commands should extend
Command
, each command is composed of zero or multiple syntaxes, and each syntax is composed of one or more arguments.If you find it confusing, here are a few examples:
/health // This is a command
/health set 50; // This is a command and its syntax
set // This is a literal argument
~ ~ ~ // This is a position argument
First of all, create your command class!
package demo.commands;
import net.minestom.server.command.builder.Command;
public class TestCommand extends Command {
public TestCommand() {
super("my-command", "hey");
// "my-command" is the main name of the command
// "hey" is an alias, you can have an unlimited number of those
}
}
After this is done, you need to register the command.
MinecraftServer.getCommandManager().register(new TestCommand());
Nothing crazy so far, let's create a callback once the command is run without any argument and another for our custom syntax.
package demo.commands;