The Command Manager

The CommandManager 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 CommandManager#register(Object, CommandCallable, String…) 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.

import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandManager;

PluginContainer plugin = ...;

CommandManager cmdManager = Sponge.getCommandManager();
cmdManager.register(plugin, myCommandSpec, "alias1", "alias2", "alias3");


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 CommandManager can also be used to call a command programmatically:

cmdManager.process(player, "msg Notch hi notch!");

You can also send a command from the server console:

cmdManager.process(Sponge.getServer().getConsole(), "kill Notch");