From 45966d1d1e56f54ad614f50a5c7d9c7574ff2e45 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Mon, 13 Nov 2017 14:38:38 +0100 Subject: [PATCH] Changed custom suggestions to be nullable --- .../builder/RequiredArgumentBuilder.java | 7 +------ .../brigadier/tree/ArgumentCommandNode.java | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/mojang/brigadier/builder/RequiredArgumentBuilder.java b/src/main/java/com/mojang/brigadier/builder/RequiredArgumentBuilder.java index 694f256..6e619d8 100644 --- a/src/main/java/com/mojang/brigadier/builder/RequiredArgumentBuilder.java +++ b/src/main/java/com/mojang/brigadier/builder/RequiredArgumentBuilder.java @@ -5,11 +5,6 @@ import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.tree.ArgumentCommandNode; import com.mojang.brigadier.tree.CommandNode; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; -import java.util.function.Function; - public class RequiredArgumentBuilder extends ArgumentBuilder> { private final String name; private final ArgumentType type; @@ -30,7 +25,7 @@ public class RequiredArgumentBuilder extends ArgumentBuilder getSuggestionsProvider() { - return suggestionsProvider == null ? type::listSuggestions : suggestionsProvider; + return suggestionsProvider; } @Override diff --git a/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java b/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java index 3fa97bc..20f8a78 100644 --- a/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java +++ b/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java @@ -21,13 +21,13 @@ public class ArgumentCommandNode extends CommandNode { private final String name; private final ArgumentType type; - private final CommandSuggestions.Provider suggestionsProvider; + private final CommandSuggestions.Provider customSuggestions; - public ArgumentCommandNode(final String name, final ArgumentType type, final Command command, final Predicate requirement, final CommandNode redirect, final RedirectModifier modifier, final CommandSuggestions.Provider suggestionsProvider) { + public ArgumentCommandNode(final String name, final ArgumentType type, final Command command, final Predicate requirement, final CommandNode redirect, final RedirectModifier modifier, final CommandSuggestions.Provider customSuggestions) { super(command, requirement, redirect, modifier); this.name = name; this.type = type; - this.suggestionsProvider = suggestionsProvider; + this.customSuggestions = customSuggestions; } public ArgumentType getType() { @@ -44,6 +44,10 @@ public class ArgumentCommandNode extends CommandNode { return USAGE_ARGUMENT_OPEN + name + USAGE_ARGUMENT_CLOSE; } + public CommandSuggestions.Provider getCustomSuggestions() { + return customSuggestions; + } + @Override public void parse(final StringReader reader, final CommandContextBuilder contextBuilder) throws CommandSyntaxException { final int start = reader.getCursor(); @@ -56,7 +60,11 @@ public class ArgumentCommandNode extends CommandNode { @Override public CompletableFuture> listSuggestions(final CommandContext context, final String command) { - return suggestionsProvider.getSuggestions(context, command); + if (customSuggestions == null) { + return type.listSuggestions(context, command); + } else { + return customSuggestions.getSuggestions(context, command); + } } @Override @@ -64,7 +72,7 @@ public class ArgumentCommandNode extends CommandNode { final RequiredArgumentBuilder builder = RequiredArgumentBuilder.argument(name, type); builder.requires(getRequirement()); builder.redirect(getRedirect(), getRedirectModifier()); - builder.suggests(suggestionsProvider); + builder.suggests(customSuggestions); if (getCommand() != null) { builder.executes(getCommand()); }