CommandExecutor

This is a guide on the CommandExecutor interface.

What is CommandExecutor ?

CommandExecutor is an interface used to execute your commands and to manage the completions of its arguments. It contains two methods which we will see in more details in the rest of this guide.

This interface is not the same as the one used by Bukkit !

The onCommand() method

This method is used to execute your command. It returns a boolean to find out if your command has been correctly executed or not.

Indeed, onCommand() method returns true if your command has been correctly executed without user error. However, if user makes errors by using your command, it will returns false. In this case, if you're using CommandUsage , it will use the advanced command aid system to help the user by showing the right usages.

These parameters

Type

Parameter

Description

SmartCommand

command

The command executed by a user (see here for more information)

CommandIssuer

issuer

The command issuer (see here for more information)

String

label

The name of the executed command (original name or aliases)

String[]

args

The arguments of the command

Example

Let's see an example with a basic /test command:

@Override
public boolean onCommand(SmartCommand command, CommandIssuer issuer, String label, String[] args) {

    //Command correctly used
    if(args.length == 0) {
        issuer.sendMessage("You passed the test !");
        return true;
    }
    //Bad usage of the command. It will send help to the issuer if you're
    //using a command resource file with a CommandUsage section.
    return false;
}

The onTabComplete() method

This method is used to send tab completions to a CommandSender. It can be very useful to create your own completions when you're not using the automatic tab completor.

This method is useless if you're using the automatic tab completor because the system already supports all the possible completions.

These parameters

Type

Parameter

Description

SmartCommand

command

The command a user wants to tab complete the arguments

CommandSender

sender

The user who wants to tab complete the command arguments

String

label

The from of the command (original name or aliases)

String[]

args

The arguments of the command

List<String>

found

The completions found for these arguments

If this method returns a list, it will override the completions found by the automatic tab completer instead of adding them.

Last updated