Skip to content

Command creation

Hxncus edited this page Jan 16, 2025 · 3 revisions

AdvancedCommand

The class is an advanced abstraction for managing commands in Minecraft. It extends CommandExecutor and TabCompleter, offering additional methods to customize commands, subcommands, arguments, and handlers.

Core Methods

Command Information

  • getName()
    Returns the name of the command.

  • getPermission()
    Returns the permission required to execute the command.

  • getPermissionMessage()
    Returns the message displayed when the player lacks the required permission.

  • getCommand()
    Returns the Command object associated with this command.

  • getAliases()
    Returns a list of aliases (shortcuts) for the command.

Command Configuration

All methods return the ICommand object, allowing method chaining.

  • description(String description)
    Sets the command description.

  • label(String label)
    Sets the command label.

  • permission(String permission)
    Sets the required permission.

  • permissionMessage(String permissionMessage)
    Sets the message displayed when permission is denied.

  • usage(String usage)
    Defines the usage template for the command.

  • addAlias(String alias)
    Adds a single alias to the command.

  • addAliases(String... aliases)
    Adds multiple aliases to the command.

Subcommand Management

  • getSubCommands()
    Returns a map of subcommands (Map<String, ICommand>).

  • getSubCommand(String subCommandName)
    Retrieves a specific subcommand by its name.

  • subCommand(ICommand subCommand)
    Adds a single subcommand.

  • subCommands(ICommand... subCommands)
    Adds multiple subcommands.

Argument Management

  • getArguments()
    Returns a list of arguments (List<Argument<?>>).

  • getArgument(String argumentName)
    Retrieves a specific argument by its name.

  • argument(Argument<T> argument)
    Adds a single argument to the command.

  • arguments(Argument<?>... arguments)
    Adds multiple arguments to the command.

Executors and Completers

  • getExecutors()
    Returns a list of command executors.

  • getCompleters()
    Returns a list of tab completers.

  • execute(CommandExecutor executor)
    Adds a command execution handler.

  • complete(TabCompleter completer)
    Adds a tab completion handler.

Example Usage

new AdvancedCommand(”test”)
    .description("Example command")
    .label("example")
    .permission("example.use")
    .permissionMessage("You don't have permission!")
    .addAlias("ex")
    .argument(new StringArgument("player"))
    .execute((sender, args) -> {
        sender.sendMessage("Command executed!");
        return true;
    })
    .complete((sender, args) -> List.of("player1", "player2")).register();

Benefits of Using

•	Simplifies the setup and management of commands with method chaining.
•	Easily supports adding subcommands and arguments.
•	Separates execution and tab completion logic for better organization.

Clone this wiki locally