Skip to content

[Brigadier] Document the command dispatcher #532

Open
@Strokkur424

Description

@Strokkur424

Note

This issue is part of a series of issues regarding the extension of the Paper documentation regarding Paper's Brigadier API.

The command dispatcher is retrievable using Commands#getDispatcher(). With it, one can query/modify/register commands. It can also just be used to work with the root command node in general.

All of its methods should be explained. An example on how to use most of them does not have to be given, since the usage of the dispatcher assumes a user to have general knowledge about the internal functionality of commands.

Though, an example for extending existing commands can be given. For this, one could extend a vanilla command to include their own sub command. Perhaps, this could be done for the /effect vanilla command:

final CommandDispatcher<CommandSourceStack> dispatcher = commands.getDispatcher();
if (dispatcher.getRoot().getChild("effect") instanceof LiteralCommandNode<CommandSourceStack> literalNode) {
    dispatcher.register(literalNode.createBuilder().then(Commands.literal("clearall")
        .executes(ctx -> {
            Bukkit.getOnlinePlayers().forEach(Player::clearActivePotionEffects);
            ctx.getSource().getSender().sendRichMessage("<gold>Successfully reset everyone's potion effects!");
            return Command.SINGLE_SUCCESS;
        })
    ));
}

Image

Warning

I myself also haven't yet 100% figured out the dispatcher either. There might be a cleaner way to do what I did here. Iif so, please comment it on this issue 🚀

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions