> For the complete documentation index, see [llms.txt](https://syrows-development.gitbook.io/smartcommands/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://syrows-development.gitbook.io/smartcommands/commands/commandexecutor.md).

# 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.

{% hint style="warning" %}
This interface is not the same as the one used by Bukkit !
{% endhint %}

### 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.&#x20;

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](https://syrows-development.gitbook.io/smartcommands/commands/commandissuer) 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:

```java
@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](https://syrows-development.gitbook.io/smartcommands/contents/commandusage/automatic-tab-completor).

{% hint style="info" %}
This method is **useless** if you're using the **automatic tab completor** because the system already **supports** all the possible completions.
{% endhint %}

#### 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                |

{% hint style="warning" %}
If this method returns a list, it will **override** the completions found by the automatic tab completer instead of adding them.
{% endhint %}
