Changed custom suggestions to be nullable
This commit is contained in:
parent
1ce9894c07
commit
45966d1d1e
2 changed files with 14 additions and 11 deletions
|
@ -5,11 +5,6 @@ import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
import com.mojang.brigadier.tree.ArgumentCommandNode;
|
import com.mojang.brigadier.tree.ArgumentCommandNode;
|
||||||
import com.mojang.brigadier.tree.CommandNode;
|
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<S, T> extends ArgumentBuilder<S, RequiredArgumentBuilder<S, T>> {
|
public class RequiredArgumentBuilder<S, T> extends ArgumentBuilder<S, RequiredArgumentBuilder<S, T>> {
|
||||||
private final String name;
|
private final String name;
|
||||||
private final ArgumentType<T> type;
|
private final ArgumentType<T> type;
|
||||||
|
@ -30,7 +25,7 @@ public class RequiredArgumentBuilder<S, T> extends ArgumentBuilder<S, RequiredAr
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandSuggestions.Provider<S> getSuggestionsProvider() {
|
public CommandSuggestions.Provider<S> getSuggestionsProvider() {
|
||||||
return suggestionsProvider == null ? type::listSuggestions : suggestionsProvider;
|
return suggestionsProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -21,13 +21,13 @@ public class ArgumentCommandNode<S, T> extends CommandNode<S> {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final ArgumentType<T> type;
|
private final ArgumentType<T> type;
|
||||||
private final CommandSuggestions.Provider<S> suggestionsProvider;
|
private final CommandSuggestions.Provider<S> customSuggestions;
|
||||||
|
|
||||||
public ArgumentCommandNode(final String name, final ArgumentType<T> type, final Command<S> command, final Predicate<S> requirement, final CommandNode<S> redirect, final RedirectModifier<S> modifier, final CommandSuggestions.Provider<S> suggestionsProvider) {
|
public ArgumentCommandNode(final String name, final ArgumentType<T> type, final Command<S> command, final Predicate<S> requirement, final CommandNode<S> redirect, final RedirectModifier<S> modifier, final CommandSuggestions.Provider<S> customSuggestions) {
|
||||||
super(command, requirement, redirect, modifier);
|
super(command, requirement, redirect, modifier);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.suggestionsProvider = suggestionsProvider;
|
this.customSuggestions = customSuggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArgumentType<T> getType() {
|
public ArgumentType<T> getType() {
|
||||||
|
@ -44,6 +44,10 @@ public class ArgumentCommandNode<S, T> extends CommandNode<S> {
|
||||||
return USAGE_ARGUMENT_OPEN + name + USAGE_ARGUMENT_CLOSE;
|
return USAGE_ARGUMENT_OPEN + name + USAGE_ARGUMENT_CLOSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommandSuggestions.Provider<S> getCustomSuggestions() {
|
||||||
|
return customSuggestions;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException {
|
public void parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException {
|
||||||
final int start = reader.getCursor();
|
final int start = reader.getCursor();
|
||||||
|
@ -56,7 +60,11 @@ public class ArgumentCommandNode<S, T> extends CommandNode<S> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Collection<String>> listSuggestions(final CommandContext<S> context, final String command) {
|
public CompletableFuture<Collection<String>> listSuggestions(final CommandContext<S> context, final String command) {
|
||||||
return suggestionsProvider.getSuggestions(context, command);
|
if (customSuggestions == null) {
|
||||||
|
return type.listSuggestions(context, command);
|
||||||
|
} else {
|
||||||
|
return customSuggestions.getSuggestions(context, command);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,7 +72,7 @@ public class ArgumentCommandNode<S, T> extends CommandNode<S> {
|
||||||
final RequiredArgumentBuilder<S, T> builder = RequiredArgumentBuilder.argument(name, type);
|
final RequiredArgumentBuilder<S, T> builder = RequiredArgumentBuilder.argument(name, type);
|
||||||
builder.requires(getRequirement());
|
builder.requires(getRequirement());
|
||||||
builder.redirect(getRedirect(), getRedirectModifier());
|
builder.redirect(getRedirect(), getRedirectModifier());
|
||||||
builder.suggests(suggestionsProvider);
|
builder.suggests(customSuggestions);
|
||||||
if (getCommand() != null) {
|
if (getCommand() != null) {
|
||||||
builder.executes(getCommand());
|
builder.executes(getCommand());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue