Fix suggestions showing twice on spigot+brigadier
Signed-off-by: Irmo van den Berge <irmo.vandenberge@ziggo.nl>
This commit is contained in:
parent
f09e0ce8f7
commit
b29d1ae5d1
1 changed files with 14 additions and 17 deletions
|
|
@ -63,7 +63,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -73,6 +72,7 @@ import java.util.function.BiPredicate;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manager used to map cloud {@link Command}
|
* Manager used to map cloud {@link Command}
|
||||||
|
|
@ -375,8 +375,8 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
.getCommandTree().getNamedNode(cloudCommand.getArguments().get(0).getName());
|
.getCommandTree().getNamedNode(cloudCommand.getArguments().get(0).getName());
|
||||||
final SuggestionProvider<S> provider = (context, builder) -> this.buildSuggestions(
|
final SuggestionProvider<S> provider = (context, builder) -> this.buildSuggestions(
|
||||||
context,
|
context,
|
||||||
|
null, /* parent node, null for the literal command node root */
|
||||||
node.getValue(),
|
node.getValue(),
|
||||||
Collections.emptySet(),
|
|
||||||
builder
|
builder
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -503,17 +503,6 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
)))
|
)))
|
||||||
.executes(executor);
|
.executes(executor);
|
||||||
} else {
|
} else {
|
||||||
// Check for sibling literals (StaticArgument)
|
|
||||||
// These are important when providing suggestions
|
|
||||||
final Set<String> siblingLiterals = (root.getParent() == null) ? Collections.emptySet()
|
|
||||||
: root.getParent().getChildren().stream()
|
|
||||||
.filter(n -> n.getValue() instanceof StaticArgument)
|
|
||||||
.map(n -> (StaticArgument<C>) ((CommandArgument) n.getValue()))
|
|
||||||
.flatMap(s -> s.getAliases().stream())
|
|
||||||
.sorted()
|
|
||||||
.distinct()
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
|
|
||||||
// Register argument
|
// Register argument
|
||||||
final Pair<ArgumentType<?>, Boolean> pair = this.getArgument(
|
final Pair<ArgumentType<?>, Boolean> pair = this.getArgument(
|
||||||
root.getValue().getValueType(),
|
root.getValue().getValueType(),
|
||||||
|
|
@ -524,8 +513,8 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
? null
|
? null
|
||||||
: (context, builder) -> this.buildSuggestions(
|
: (context, builder) -> this.buildSuggestions(
|
||||||
context,
|
context,
|
||||||
|
root.getParent(),
|
||||||
root.getValue(),
|
root.getValue(),
|
||||||
siblingLiterals,
|
|
||||||
builder
|
builder
|
||||||
);
|
);
|
||||||
argumentBuilder = RequiredArgumentBuilder
|
argumentBuilder = RequiredArgumentBuilder
|
||||||
|
|
@ -554,8 +543,8 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
|
|
||||||
private @NonNull CompletableFuture<Suggestions> buildSuggestions(
|
private @NonNull CompletableFuture<Suggestions> buildSuggestions(
|
||||||
final com.mojang.brigadier.context.@Nullable CommandContext<S> senderContext,
|
final com.mojang.brigadier.context.@Nullable CommandContext<S> senderContext,
|
||||||
|
final CommandTree.@Nullable Node<CommandArgument<C, ?>> parentNode,
|
||||||
final @NonNull CommandArgument<C, ?> argument,
|
final @NonNull CommandArgument<C, ?> argument,
|
||||||
final @NonNull Set<String> siblingLiterals,
|
|
||||||
final @NonNull SuggestionsBuilder builder
|
final @NonNull SuggestionsBuilder builder
|
||||||
) {
|
) {
|
||||||
final CommandContext<C> commandContext;
|
final CommandContext<C> commandContext;
|
||||||
|
|
@ -586,9 +575,17 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
command
|
command
|
||||||
);
|
);
|
||||||
|
|
||||||
/* Filter suggetions that are literal arguments to avoid duplicates */
|
/* Filter suggestions that are literal arguments to avoid duplicates, except for root arguments */
|
||||||
final List<String> suggestions = new ArrayList<>(suggestionsUnfiltered);
|
final List<String> suggestions = new ArrayList<>(suggestionsUnfiltered);
|
||||||
|
if (parentNode != null) {
|
||||||
|
final Set<String> siblingLiterals = parentNode.getChildren().stream()
|
||||||
|
.map(CommandTree.Node::getValue)
|
||||||
|
.flatMap(arg -> (arg instanceof StaticArgument)
|
||||||
|
? ((StaticArgument<C>) arg).getAliases().stream() : Stream.empty())
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
suggestions.removeIf(siblingLiterals::contains);
|
suggestions.removeIf(siblingLiterals::contains);
|
||||||
|
}
|
||||||
|
|
||||||
SuggestionsBuilder suggestionsBuilder = builder;
|
SuggestionsBuilder suggestionsBuilder = builder;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue