Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Brigadier] Document the command dispatcher #532

Open
Strokkur424 opened this issue Jan 22, 2025 · 0 comments
Open

[Brigadier] Document the command dispatcher #532

Strokkur424 opened this issue Jan 22, 2025 · 0 comments

Comments

@Strokkur424
Copy link
Contributor

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 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant