CommandAPI
CommandAPI copied to clipboard
Hidden Command
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
We already have a similar issue open: https://github.com/JorelAli/CommandAPI/issues/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.
Yeah, subcommands are converted into LiteralArgument
s, 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.