Skip to content
This repository was archived by the owner on Dec 11, 2024. It is now read-only.

Command

Syrent edited this page Jun 24, 2023 · 4 revisions

Command

The Command class is used to create and manage commands in your Minecraft plugin. This document provides an overview of the Command class and its usage.

Dependencies

The Command class relies on the cloud framework for command management. The cloud framework provides a powerful set of tools and utilities for creating and handling commands. You can find more information about the cloud framework in the Cloud Wiki.

Usage

Here's an example usage of the Command class:

public class ExampleCommand extends Command {

    public ExampleCommand() {
        super("foo", "fooaliases1", "fooaliases2");

        Command barLiteral = this.addLiteral("bar", ArgumentDescription.of("Just a simple bar literal for foo command"), "barliteral", "baraliases")
                .permission(this.getPermission("bar"))
                .argument(StringArgument.<ISender>builder("exampleargument").withSuggestionsProvider((context, command) -> {
                    return List.of("argument1", "argument2", "argument3");
                }))
                .flag(CommandFlag.builder("rainbow").withAliases("r"))
                .handler((context) -> {
                    ISender sender = context.getSender();

                    if (!(sender instanceof Player)) {
                        return;
                    }

                    Player player = (Player) sender;
                    String argument = context.getOptional("bar");
                    boolean flag = context.flags().hasFlag("rainbow");

                    player.sendMessage(ComponentUtils.component((flag ? "<rainbow>" : "<green>") + "Hello, World! " + (argument.isPresent() ? "<gold>(with bar argument)" : "")));
                });

        this.saveCommand(barLiteral);
    }

}

Additional Resources

  • Cloud Wiki - Documentation for the cloud framework used in Origin API.

Clone this wiki locally