# Command dispatcher

`CommandDispatcher` will fill every PlaceholderAPI placeholder if PAPI is installed. It also supports legacy and MiniMessage color formats if the command type is `message` . It can also interact with the built-in user metadata. By default, if no prefix is specified at the start of the command, it will be a console command.

## Prefixes

Prefixes define how should a command be executed or what it does. For example, it can be a console command, a player performed command, a simple message to a player, or meta data modification, or even just a placeholder parsing operation.

### Console

Executes the command in the console. Placeholders are supported.

```
[console] say Hi %player_name%
```

### Player

Executes the command as the player. Placeholders are supported.

```
[player] level milestones
```

### Message

Sends a message to the player. Placeholders and every type of color codes are supported.

```
[message] &6Hey what's up %player_name%? <#3d3d3d>MiniMessage also supported!
```

### Actionbar

Sends a message to the players actionbar. Placeholders and every type of color codes are supported.

```
[actionbar] &6Hey what's up %player_name%? <#3d3d3d>MiniMessage also supported!
```

### Sound

Play a sound for the player. Sound - volume -pitch

```
[sound] entity.villager.yes 1 1
```

### Close

Closes the currently open inventory. Useful for menus.

```
[close]
```

### Placeholder

parses a placeholder. Can be useful to start placeholder-based cooldown or something.

```
[placeholder] %player_name%
```

### Give money

Give money to the player. (Economy argument can be omitted)

```
[give-money] 1000 economy={Vault}
```

### Take money

Withdraw money from the player. (Economy argument can be omitted)

```
[take-money] 1000 economy={Vault}
```

### Open gui menu

Opens a custom AuroraLib powered GUI menu for the player. Arguments after the menu id are optional.

```
[open-gui] menu_id test={example} arg2={100}
```

### Take items

Take items from the player's inventory. This only supports custom items, defined in [item-config](https://docs.auroramc.gg/aurora/item-config "mention"). List your items separated by spaces and add /number at the end to specify how many of those item should be taken from the player's inventory.

```yaml
[take-items] oraxen:some_item/32 mythicmobs:super_sword/1
```

### Give item

Gives an item to the player. This only supports custom items, defined in [item-config](https://docs.auroramc.gg/aurora/item-config "mention"). Add /number at the end to specify how many of that item should be added to the player's inventory. If the items don't fit in the player's inventory, then the item will be dropped to the ground. If you add `true` at the end, it will add excess items to the player's stash instead. This is not recommended though since they can easily overwhelm the stash.

```yaml
[give-item] oraxen:some_item/32
[give-item] oraxen:some_item/32 true
```

### Meta set

Sets or overrides a meta value for the given key for the user.

```
[meta:set:mymeta] value (single number or text)
```

### Meta remove

Removes a meta key from the user.

```
[meta:remove:mymetakey]
```

### Meta increment

Increments a meta value by the provided number or 1 if there isn't any provided value. If the meta doesn't exist it will be created.

```
[meta:increment:mymetakey] optional number here
```

### Meta decrement

Decrements a meta value by the provided number or 1 if there isn't any provided value. If the meta doesn't exist it will be created. It doesn't allow it to go below 0.

```
[meta:decrement:mymetakey] optional number here
```

## API Usage

You can register custom prefix handlers or even override the default ones.

```java
AuroraAPI.registerCommandDispatcherActionHandler("my-prefix", (player, input) -> {
  // Do something. Note that your prefix is already removed here from the input
});
```

Then you can write something like this in your configs everywhere:

```yaml
on-click:
  - "[my-prefix] this is the input string"
```
