Search in sources :

Example 1 with SpongeCommandCompletion

use of org.spongepowered.common.command.SpongeCommandCompletion in project SpongeCommon by SpongePowered.

the class SpongeArgumentCommandNode method suggestUsingModifier.

private CompletableFuture<Suggestions> suggestUsingModifier(final CommandContext<?> context, final SuggestionsBuilder suggestionsBuilder, final CompletableFuture<Suggestions> suggestions) {
    if (this.modifier != null) {
        return suggestions.thenApply(x -> {
            final List<CommandCompletion> originalSuggestions = x.getList().stream().map(SpongeCommandCompletion::from).collect(Collectors.toList());
            final List<CommandCompletion> modifiedSuggestions = this.modifier.modifyCompletion((org.spongepowered.api.command.parameter.CommandContext) context, suggestionsBuilder.getRemaining(), new ArrayList<>(originalSuggestions));
            if (originalSuggestions.equals(modifiedSuggestions)) {
                return x;
            }
            final SuggestionsBuilder newBuilder = suggestionsBuilder.restart();
            for (final CommandCompletion suggestion : modifiedSuggestions) {
                newBuilder.suggest(suggestion.completion(), suggestion.tooltip().map(SpongeAdventure::asVanilla).orElse(null));
            }
            return newBuilder.build();
        });
    }
    return suggestionsBuilder.buildFuture();
}
Also used : SpongeAdventure(org.spongepowered.common.adventure.SpongeAdventure) SpongeCommandCompletion(org.spongepowered.common.command.SpongeCommandCompletion) CommandCompletion(org.spongepowered.api.command.CommandCompletion) SuggestionsBuilder(com.mojang.brigadier.suggestion.SuggestionsBuilder)

Aggregations

SuggestionsBuilder (com.mojang.brigadier.suggestion.SuggestionsBuilder)1 CommandCompletion (org.spongepowered.api.command.CommandCompletion)1 SpongeAdventure (org.spongepowered.common.adventure.SpongeAdventure)1 SpongeCommandCompletion (org.spongepowered.common.command.SpongeCommandCompletion)1