Search in sources :

Example 1 with Message

use of com.mojang.brigadier.Message in project SpongeCommon by SpongePowered.

the class CommandUtil method buildSuggestionsFromCompletions.

public static CompletableFuture<Suggestions> buildSuggestionsFromCompletions(final List<CommandCompletion> commandCompletions, final SuggestionsBuilder builder) {
    for (final CommandCompletion completion : commandCompletions) {
        final String s = completion.completion();
        final Message m = completion.tooltip().map(SpongeAdventure::asVanilla).orElse(null);
        if (CommandUtil.INTEGER_PATTERN.matcher(s).matches()) {
            try {
                builder.suggest(Integer.parseInt(s), m);
            } catch (final NumberFormatException ex) {
                builder.suggest(s, m);
            }
        } else {
            builder.suggest(s, m);
        }
    }
    return builder.buildFuture();
}
Also used : Message(com.mojang.brigadier.Message) CommandCompletion(org.spongepowered.api.command.CommandCompletion)

Aggregations

Message (com.mojang.brigadier.Message)1 CommandCompletion (org.spongepowered.api.command.CommandCompletion)1