CommandAPI icon indicating copy to clipboard operation
CommandAPI copied to clipboard

Exclude desired subcommands from suggestions

Open owljacob opened this issue 2 years ago • 1 comments

Description

It all consists of the ability to modify the suggestions of subcommands... like to suggest some of them only instead of every single one that is provided.

Expected code

No response

Extra details

No response

owljacob avatar Jan 21 '23 10:01 owljacob

So yeah, subcommands are converted into LiteralArguments, and when Brigadier finds a literal in the command tree, it drops it directly into the list of suggestions. Looking at the code, this is the method used to get the suggestions for a literal command node: LiteralCommandNode.java#L70-L77

@Override
public CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> context, final SuggestionsBuilder builder) {
    if (literalLowerCase.startsWith(builder.getRemainingLowerCase())) {
        return builder.suggest(literal).buildFuture();
    } else {
        return Suggestions.empty();
    }
}

The return builder.suggest(literal).buildFuture(); part adds the name of the subcommand (literal) into the list of suggestions. That code always runs, except when the text the user input isn't the start of the literal. Most important for this issue, it isn't possible to stop the literal from showing up whenever we want; there just isn't a check for that.

It may be possible to hide subcommands if they were converted to use something that wasn't a literal argument, but I'm not sure how that would work out.

willkroboth avatar Jan 23 '23 16:01 willkroboth