> For the complete documentation index, see [llms.txt](https://vulkan-technologies.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vulkan-technologies.gitbook.io/documentation/vulkan-menu/configuration/command-registration.md).

# Command registration

VulkanMenu allows you to register custom commands for opening menus directly from the menu configuration. This makes it easy to create menu-specific commands without needing to modify plugin code.

## Basic Command Registration

Commands are registered using the `open-command` section in your menu configuration file.

### Simple Command

The most basic command setup requires only a name:

```yaml
open-command:
  name: shop
```

This creates the command `/shop` that opens the menu.

### Command with Aliases

You can add alternative command names using aliases:

```yaml
open-command:
  name: shop
  aliases:
    - store
    - market
    - buy
```

Players can now use `/shop`, `/store`, `/market`, or `/buy` to open the same menu.

### Command with Description

Add a description that appears in the `/help` menu:

```yaml
open-command:
  name: warps
  description: "Open the server warps menu"
```

### Complete Example

Here's a full command configuration with all options:

```yaml
open-command:
  name: settings
  aliases:
    - config
    - options
    - prefs
  description: "Open your personal settings menu"
```

## Command Requirements

While the command itself doesn't have built-in permission requirements, you can control access using `open-requirements`:

```yaml
open-command:
  name: admin
  description: "Administrative control panel"

open-requirements:
  permission:
    requirement: "[permission] admin.menu"
    deny-actions:
      - "[message] <red>You don't have permission to use this command!"
```

## Multiple Menus with Commands

Each menu can have its own command. Create multiple menu files to register multiple commands:

**menus/shop.yml:**

```yaml
title: "<green>Shop"
size: 54
open-command:
  name: shop
```

**menus/warps.yml:**

```yaml
title: "<blue>Warps"
size: 27
open-command:
  name: warps
```

## Command Naming Rules

### Valid Command Names

* Must be a single word (no spaces)
* Can contain letters, numbers, and underscores
* Should be lowercase for consistency
* Must be unique (not conflict with other commands)

### Invalid Command Names

```yaml
# ❌ Contains space
open-command:
  name: "my menu"

# ❌ Contains special characters
open-command:
  name: "menu-test"

# ✅ Valid alternatives
open-command:
  name: mymenu
  # or
  name: menu_test
```

## Command Arguments

Currently, VulkanMenu commands don't support custom arguments. However, you can open menus for other players using the built-in `/vmenu open` command:

```bash
/vmenu open <player> <menu>
```

## Command Conflicts

### Checking for Conflicts

If a command name is already registered by another plugin, VulkanMenu will log a warning:

```
[VulkanMenu] Warning: Command 'shop' is already registered by another plugin
```

### Resolution Strategies

1. **Use a different name:**

```yaml
open-command:
  name: vshop  # Prefixed with 'v' for VulkanMenu
```

2. **Use aliases if the main command is taken:**

```yaml
open-command:
  name: vulkanshop
  aliases:
    - vshop
```

3. **Disable the conflicting plugin's command** (if possible) and use VulkanMenu's version

## Dynamic Command Registration

Commands are automatically registered when:

* The server starts
* The plugin is reloaded (`/vmenu reload`)
* A new menu file is added (with live-reload enabled)

Commands are automatically unregistered when:

* The menu file is deleted
* The command configuration is removed from the menu
* The plugin is disabled

## Advanced Usage

### Conditional Command Registration

You can combine command registration with PlaceholderAPI for dynamic behavior:

```yaml
title: "<green>%player_name%'s Shop"
size: 54

open-command:
  name: playershop
  description: "Open your personal shop"

open-requirements:
  level:
    requirement: "[compare] %player_level% >= 10"
    deny-actions:
      - "[message] <red>You must be level 10 to access the shop!"
```

### Command Override

If you need to override an existing VulkanMenu command, simply create a new menu with the same command name. The newest loaded menu will take precedence.

## Best Practices

1. **Use descriptive names**: Choose command names that clearly indicate the menu's purpose
2. **Keep it short**: Shorter commands are easier for players to remember and type
3. **Be consistent**: Use a naming convention across all your menu commands
4. **Document commands**: Always include descriptions for better user experience
5. **Test for conflicts**: Check that your commands don't conflict with essential server commands

## Examples

### Shop Menu Command

```yaml
title: "<gradient:#00ff00:#ffff00>Server Shop"
size: 54
open-command:
  name: shop
  aliases:
    - store
    - buy
    - sell
  description: "Browse and purchase items from the server shop"
```

### Warp Menu Command

```yaml
title: "<aqua>Teleportation Hub"
size: 27
open-command:
  name: warps
  aliases:
    - warp
    - tp
    - teleport
  description: "Teleport to various server locations"
```

### Admin Menu Command

```yaml
title: "<dark_red>Admin Panel"
size: 45
open-command:
  name: admin
  description: "Server administration panel"
  
open-requirements:
  admin_permission:
    requirement: "[permission] vulkanmenu.admin"
    deny-actions:
      - "[message] <red>This command is for administrators only!"
```

## Troubleshooting

### Command not working

* Ensure the menu file is properly formatted (valid YAML)
* Check that the command name doesn't contain spaces or special characters
* Verify the menu file is in the correct directory (`plugins/VulkanMenu/menus/`)
* Look for errors in the console during startup or reload

### Command conflicts

* Check which plugin owns the conflicting command
* Consider using a unique prefix for all VulkanMenu commands
* Use aliases as alternative access methods

### Changes not applying

* Run `/vmenu reload` to reload all menus
* Enable live-reload for automatic updates
* Check console for any error messages during reload
