bukkit Commands Handling a Command


To handle a command, you must have a class that implements the CommandExecutor interface. The JavaPlugin class (your plugin's main class) already implements this.

When implementing the CommandExecutor interface, the following method must be implemented:

public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
//Handle your command in here
return true;      ///Should return false if you want to show the usage


Sender is the one who sent the command. It can be a Player or the Console.

CMD is the command you're listening to, as declared in plugin.yml. Not to be confused with label.

label is the alias used to execute this command, it's what the sender types after the slash.

and finally, args are the arguments the sender may have used to send your command.

A possible command might go as

/tell Kerooker Hi, Kerooker!

Tell would be your label, and may also be defined as your command if you said so in plugin.yml;

'Kerooker', 'Hi,' , 'Kerooker!' are your args 0, 1 and 2, respectively

As a return, you will probably always want to return true when you expected everything to happen that way. You should return false if you want to show the sender the the command usage defined in your plugin.yml