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();
}
Aggregations