---
description: This is an example of what you can do using SmartCommands.
---

# Example of use

### Initialize the API

```java
SmartCommandsAPI api = new SmartCommandsAPI.ApiBuilder().build(this);
```

### Create your command

In this example, I will create a `/item` command so the name of my command is `item`.

{% code title="commands.json" %}
```java
{
  "item": {
    "description": "A command to customize your items.",
    "usage": "/item",
    "resource": "commands/command_item.json",
    "resourceOnly": false,
    "aliases": ["it"],
    "issuers": ["PLAYER"],
    "tabComplete": true
  }
}
```
{% endcode %}

### Add contents to your command

{% code title="command_item.json" %}
```javascript
"commandUsage": {
  "name": {
    "component": {
      "text": "&6/item name &e[name] &7to rename your item.",
      "showText": "&bClick to suggest",
      "suggestCommand": "item name",
      "color": "GRAY"
    },
    "permission": "item.name",
    "type": "Usage.class"
  },
  "clear": {
    "component": {
      "text": "&6/item clear &7to remove all the attributes of your team.",
      "showText": "&bClick to execute",
      "runCommand": "item clear",
      "color": "GRAY"
    },
    "permission": "item.clear",
    "type": "Usage.class"
  },
  "lore": {
    "list": {
      "component": {
        "text": "&6/item lore list &7to show the lore your the item.",
        "showText": "&bClick to execute",
        "runCommand": "item lore list",
        "color": "GRAY"
      },
      "permission": "item.lore.list",
      "type": "Usage.class"
    },
    "add": {
      "component": {
        "text": "&6/item lore add &e[line] &7to add a line to your item lore.",
        "showText": "&bClick to suggest",
        "suggestCommand": "item lore add",
        "color": "GRAY"
      },
      "permission": "lore.add",
      "type": "Usage.class"
    },
    "remove": {
      "component": {
        "text": "&6/item lore remove &e[line] &7to remove a line to your item lore.",
        "showText": "&bClick to suggest",
        "suggestCommand": "item lore remove",
        "color": "GRAY"
      },
      "permission": "lore.remove",
      "type": "Usage.class"
    }
  }
}
```
{% endcode %}

### Register your command

```java
CommandManager manager = api.getCommandManager();
manager.registerCommand("item", new CommandItem());
```

### Results

#### Advanced command aid system

Here, you can see an example of use of the **advanced aid system** combined with the **page system**.

![](https://1023810235-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmATygBs_lfcHxUusr5%2F-LzXr72tJtijL3d7OrzF%2F-LzXrgkyuE2wMNdmyijQ%2Fitem_help.gif?alt=media\&token=ea33831e-dc1b-455b-bc0b-4205b248f52f)

In these examples, I made a **mistake** in the syntax of my command so the system will **automatically** show me the **closest** commands to the **one** I sent.

![](https://1023810235-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmATygBs_lfcHxUusr5%2F-LzYNNtSzs-I9oSXi1Gf%2F-LzYNTICYttTdAeIC92V%2Fitem_name.gif?alt=media\&token=def4e74f-0ace-45c9-a236-c95f3dbf0815)

![](https://1023810235-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmATygBs_lfcHxUusr5%2F-LzXrkMlsO-C6KIF6DtT%2F-LzXsprt-rhgbO2esxJ4%2Fitem_lore.gif?alt=media\&token=c3275347-7c15-4fd9-8eb9-38316cc69e73)

You can also click on the commands found by the system to **execute** them or **suggest** them.

![](https://1023810235-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmATygBs_lfcHxUusr5%2F-LzYNNtSzs-I9oSXi1Gf%2F-LzYNwK2B-86zdAvnbuD%2Fitem_clear.gif?alt=media\&token=1aa997f6-b1fc-445c-a1db-4f74d563c528)

#### Automatic tab completer

Here is an example of use of the **automatic tab completer**. As you can see it, it **automatically** found the possible completions and send them to me.

![](https://1023810235-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmATygBs_lfcHxUusr5%2F-LzYO0zo71OxzfMkJFB7%2F-LzYOMXU__moxanSMiVl%2Ftab_complete.gif?alt=media\&token=feaab6ef-3b63-4982-8e06-804191a90069)
