Skip to content

Creating Commands

honkling edited this page Jun 3, 2024 · 1 revision

Basic Commands

Commando treats each file as a command, with the functions being subcommands. The file just needs to be marked as a command.
This can be done using the Command annotation, or a registerCommando function.

Annotation

Kotlin
@file:Command("example")

package me.honkling.example.commands

private fun example(player: Player) {
  // ...
}
Java
@Command("example")
public class Example {
  public void example(Player player) {
    // ...
  }
}

Method

Kotlin
private fun registerCommando(manager: CommandManager) {
  manager.registerCommand("example")
}
Java
public class Example {
  public void registerCommando(CommandManager manager) {
    manager.registerCommand("example");
  }
}

Command properties

You may set various properties of the command, such as description, permissions, etc., using the annotation or registerCommando function mentioned above. They are just properties in the constructor.

Aliases

Annotation: @Command("example", "alias1", "alias2", ...)
Method: manager.registerCommand("example", "alias1", "alias2", ...)

Description

Annotation: @Command("example", description = "hello")
Method: manager.registerCommand("example", description = "hello")

Usage

Annotation: @Command("example", usage = "you ran it wrong")
Method: manager.registerCommand("example", usage = "you ran it wrong")
Usage handler (method exclusive): manager.registerCommand("example", usageHandler = { command: PluginCommand -> /* ... */ })

Permission

Annotation: @Command("example", permission = "commando.example")
Method: manager.registerCommand("example", permission = "commando.example")

Permission Message

Annotation: @Command("example", permissionMessage = "You don't have permission")
Method: manager.registerCommand("example", permissionMessage = "You don't have permission")

Creating subcommands

Commando treats every function as a subcommand, using the name of the function to name the subcommand.
Do note, if the function is named the same as the command itself, then it is treated as the default subcommand, meaning it can be executed with just /<command name>, as opposed to /<command name> <function name>.

Clone this wiki locally