Skip to content

Commit

Permalink
Changed custom suggestions to be nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinnerbone committed Nov 13, 2017
1 parent 1ce9894 commit 45966d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
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<S, T> extends ArgumentBuilder<S, RequiredArgumentBuilder<S, T>> {
private final String name;
private final ArgumentType<T> type;
Expand All @@ -30,7 +25,7 @@ public RequiredArgumentBuilder<S, T> suggests(final CommandSuggestions.Provider<
}

public CommandSuggestions.Provider<S> getSuggestionsProvider() {
return suggestionsProvider == null ? type::listSuggestions : suggestionsProvider;
return suggestionsProvider;
}

@Override
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public class ArgumentCommandNode<S, T> extends CommandNode<S> {

private final String name;
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);
this.name = name;
this.type = type;
this.suggestionsProvider = suggestionsProvider;
this.customSuggestions = customSuggestions;
}

public ArgumentType<T> getType() {
Expand All @@ -44,6 +44,10 @@ public String getUsageText() {
return USAGE_ARGUMENT_OPEN + name + USAGE_ARGUMENT_CLOSE;
}

public CommandSuggestions.Provider<S> getCustomSuggestions() {
return customSuggestions;
}

@Override
public void parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException {
final int start = reader.getCursor();
Expand All @@ -56,15 +60,19 @@ public void parse(final StringReader reader, final CommandContextBuilder<S> cont

@Override
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
public RequiredArgumentBuilder<S, T> createBuilder() {
final RequiredArgumentBuilder<S, T> builder = RequiredArgumentBuilder.argument(name, type);
builder.requires(getRequirement());
builder.redirect(getRedirect(), getRedirectModifier());
builder.suggests(suggestionsProvider);
builder.suggests(customSuggestions);
if (getCommand() != null) {
builder.executes(getCommand());
}
Expand Down

0 comments on commit 45966d1

Please sign in to comment.