The Command ServiceΒΆ
The CommandService stands as the manager for watching what commands get typed into chat, and redirecting them to the right command handler. To register your command, use the method CommandService.register(), passing your plugin, an instance of the command, and any needed aliases as parameters.
Usually you want to register your commands when the GameInitializationEvent is called. If you are registering the commands from the main plugin class, use this as the plugin parameter.
import org.spongepowered.api.service.command.CommandService;
CommandService cmdService = game.getCommandDispatcher();
cmdService.register(this, myCommandSpec, "alias1", "alias2", "alias3");
Note
The arguments after the new instance of your command are the aliases to register for the command. You can add as many Strings as you want. The first alias that isn’t used by another command becomes the primary alias. This means aliases used by another command are ignored.
The CommandService can also be used to call a command programatically:
cmdService.process(player, "msg Notch hi notch!");
You can also send a command from the server console:
cmdService.process(game.getServer().getConsole(), "kill Notch");