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

Hidden Command #508

Open
tanyaofei opened this issue Nov 29, 2023 · 2 comments
Open

Hidden Command #508

tanyaofei opened this issue Nov 29, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@tanyaofei
Copy link

tanyaofei commented Nov 29, 2023

Description

Sometimes I want to create ClickEvent to execute commands, and I don't want them show up in suggestions.
It's there a way to create hidden subcommands that will not show up on tab complete?

Expected code

new CommandAPICommand("system")
                .withSubcommands(
                        new CommandAPICommand("reload")
                                .executes((CommandExecutor) (sender, args) -> sender
                                        .sendMessage(Component
                                                .text("Are you sure?")
                                                .clickEvent(ClickEvent.runCommand("/system reload-confirm"))
                                        )
                                ),
                        new CommandAPICommand("reload-confirm")
                                .hidden(true) // this command will not show up in suggestions
                                .executes((CommandExecutor) (sender, args) -> Bukkit.getServer().reload())
                ).register();

Extra details

No response

@tanyaofei tanyaofei added the enhancement New feature or request label Nov 29, 2023
@DerEchtePilz
Copy link
Collaborator

We already have a similar issue open: #409
A subcommand is converted to a literal value internally which in turn is basically suggested instantly when Brigadier sees one of them.
You may also want to look into the linked issue as @willkroboth explained it a bit better than I did here.

@willkroboth
Copy link
Collaborator

Yeah, subcommands are converted into LiteralArguments, and you can't control the suggestions of literal arguments.

However, in this case, you could use a StringArgument instead with a CommandTree, like so:

new CommandTree("system")
    .then(
        new LiteralArgument("reload")
            .executes((CommandExecutor) (sender, args) -> sender
                    .sendMessage(Component
                            .text("Are you sure?")
                            .clickEvent(ClickEvent.runCommand("/system reload-confirm"))
                    )
            )
    )
    .then(
        new StringArgument("option")
            .executes((sender, args) -> {
                String choice = args.get("option");
                if("reload-confirm".equals(choice)) {
                    Bukkit.getServer().reload();
                } else {
                    throw CommandAPI.failWithString("Unknown choice: " + choice);
                }
            })
    )
    .register();

It's a bit jank, but it might work for this situation? StringArgument can have its suggestions controlled and, by default, it doesn't suggest anything.

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

No branches or pull requests

3 participants