---
description: >-
  This is a guide to learn how to create and how to use the automatic tab
  completor.
---

# Automatic tab completor

## Automatic tab completer

### What is it ?

By creating an **advanced command aid system** for your command, you also created the **automatic tab completer**. Indeed, this tab completer is based on the keys in the JSON file.&#x20;

However, to only use the **automatic tab completer**, the property `component` is optional but `type` is always mandatory. You can also add a specific permission to tab complete command arguments by using the `permission` property.

{% hint style="info" %}
If you're using a permission, completions will be sent only if the user has this permission.
{% endhint %}

{% hint style="warning" %}
The value of the property `tabComplete` must be set to `true` in the `commands.json` file to use the automatic tab completer.
{% endhint %}

### Non permanents arguments

The automatic tab completer also considers non permanents arguments. These arguments can be of two types:&#x20;

* Those which are part of a list like names of warps or names of online players.
* Those which must be written by a user like the name of an item or a line of its lore.

### Arguments which are part of a list

If an argument is a part of a list of other arguments, it must be defined between `<` and `>` symbols.&#x20;

**Examples**: `<player>`, `<warp>`, `<faction>`, ...

#### Register completions

With `SmartCommands`, you can register a list of arguments which will be sent automatically. First, when you register you command, retrieve the `SmartCommandsManager` class from the `SmartCommandsAPI` class.

```java
SmartCommandsManager scManager = api.getSmartCommandsManager();
```

Retrieve the command in which you want to register your completions.

```java
SmartCommand command = scManager.getSmartCommand("warp");
```

Now, we're ready to register our completions. We will use the registerCompletions() method from the SmartCommand class. First, let's see this method in more details.

| Parameter     | Type           | Description                     |
| ------------- | -------------- | ------------------------------- |
| `key`         | `String`       | The argument to tab complete    |
| `completions` | `List<String>` | The list of completions to send |

{% hint style="info" %}
You can also get the completions and unregister an argument if you want by using the `getCompletion(String key)` and the `unregisterCompletions(String key)` methods.
{% endhint %}

{% hint style="info" %}
The argument `<player>` is automatically replaced by the list of names of online players so you do not have to register it.
{% endhint %}

#### Example

```java
List<String> warps = Arrays.asList("nether", "end", "rules", "mining");

command.registerCompletions("<warp>", warps);
```

![](https://1023810235-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmATygBs_lfcHxUusr5%2F-Lzgsv23CSUqrMW-lDFb%2F-LzgszfQjmJAc0BBcbTV%2Flist_completions.gif?alt=media\&token=aa101c44-05e9-436d-bef6-24a6ec5d70e7)

### Arguments which must be written by a user

If an argument must be written by a user, it must be defined in square brackets.

**Examples**: `[name]`, `[line]`, ...

{% hint style="info" %}
This type of argument cannot be tab completed so completion will not be sent to users.
{% endhint %}
