Add the full input string to command context
This commit is contained in:
@@ -95,7 +95,7 @@ public class CommandDispatcher<S> {
|
||||
while (!contexts.isEmpty()) {
|
||||
final CommandContextBuilder<S> builder = contexts.removeFirst();
|
||||
final CommandContextBuilder<S> child = builder.getChild();
|
||||
final CommandContext<S> context = builder.build();
|
||||
final CommandContext<S> context = builder.build(parse.getReader().getString());
|
||||
if (child != null) {
|
||||
if (!child.getNodes().isEmpty()) {
|
||||
final RedirectModifier<S> modifier = Iterators.getLast(builder.getNodes().keySet().iterator()).getRedirectModifier();
|
||||
@@ -128,7 +128,7 @@ public class CommandDispatcher<S> {
|
||||
}
|
||||
|
||||
if (!foundCommand) {
|
||||
consumer.onCommandComplete(parse.getContext().build(), false, 0);
|
||||
consumer.onCommandComplete(parse.getContext().build(parse.getReader().getString()), false, 0);
|
||||
throw ERROR_UNKNOWN_COMMAND.createWithContext(parse.getReader());
|
||||
}
|
||||
|
||||
@@ -334,7 +334,11 @@ public class CommandDispatcher<S> {
|
||||
@SuppressWarnings("unchecked") final CompletableFuture<Collection<String>>[] futures = new CompletableFuture[parent.getChildren().size()];
|
||||
int i = 0;
|
||||
for (final CommandNode<S> node : parent.getChildren()) {
|
||||
futures[i++] = node.listSuggestions(context.build(), parse.getReader().getString().substring(start));
|
||||
try {
|
||||
futures[i++] = node.listSuggestions(context.build(parse.getReader().getString()), parse.getReader().getString().substring(start));
|
||||
} catch (final CommandSyntaxException e) {
|
||||
futures[i++] = CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
}
|
||||
|
||||
final CompletableFuture<CommandSuggestions> result = new CompletableFuture<>();
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mojang.brigadier;
|
||||
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.context.StringRange;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -49,6 +50,6 @@ public class CommandSuggestions {
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Provider<S> {
|
||||
CompletableFuture<Collection<String>> getSuggestions(final CommandContext<S> context, final String prefix);
|
||||
CompletableFuture<Collection<String>> getSuggestions(final CommandContext<S> context, final String prefix) throws CommandSyntaxException;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,14 +9,16 @@ import java.util.Map;
|
||||
|
||||
public class CommandContext<S> {
|
||||
private final S source;
|
||||
private final String input;
|
||||
private final Command<S> command;
|
||||
private final Map<String, ParsedArgument<S, ?>> arguments;
|
||||
private final Map<CommandNode<S>, StringRange> nodes;
|
||||
private final StringRange range;
|
||||
private final CommandContext<S> child;
|
||||
|
||||
public CommandContext(final S source, final Map<String, ParsedArgument<S, ?>> arguments, final Command<S> command, final Map<CommandNode<S>, StringRange> nodes, final StringRange range, final CommandContext<S> child) {
|
||||
public CommandContext(final S source, final String input, final Map<String, ParsedArgument<S, ?>> arguments, final Command<S> command, final Map<CommandNode<S>, StringRange> nodes, final StringRange range, final CommandContext<S> child) {
|
||||
this.source = source;
|
||||
this.input = input;
|
||||
this.arguments = arguments;
|
||||
this.command = command;
|
||||
this.nodes = nodes;
|
||||
@@ -82,6 +84,10 @@ public class CommandContext<S> {
|
||||
return range;
|
||||
}
|
||||
|
||||
public String getInput() {
|
||||
return input;
|
||||
}
|
||||
|
||||
public Map<CommandNode<S>, StringRange> getNodes() {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
@@ -78,8 +78,8 @@ public class CommandContextBuilder<S> {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
public CommandContext<S> build() {
|
||||
return new CommandContext<>(source, arguments, command, nodes, range, child == null ? null : child.build());
|
||||
public CommandContext<S> build(final String input) {
|
||||
return new CommandContext<>(source, input, arguments, command, nodes, range, child == null ? null : child.build(input));
|
||||
}
|
||||
|
||||
public CommandDispatcher<S> getDispatcher() {
|
||||
|
||||
@@ -59,7 +59,7 @@ public class ArgumentCommandNode<S, T> extends CommandNode<S> {
|
||||
}
|
||||
|
||||
@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) throws CommandSyntaxException {
|
||||
if (customSuggestions == null) {
|
||||
return type.listSuggestions(context, command);
|
||||
} else {
|
||||
|
||||
@@ -104,7 +104,7 @@ public abstract class CommandNode<S> implements Comparable<CommandNode<S>> {
|
||||
|
||||
public abstract void parse(StringReader reader, CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException;
|
||||
|
||||
public abstract CompletableFuture<Collection<String>> listSuggestions(CommandContext<S> context, String command);
|
||||
public abstract CompletableFuture<Collection<String>> listSuggestions(CommandContext<S> context, String command) throws CommandSyntaxException;
|
||||
|
||||
public abstract ArgumentBuilder<S, ?> createBuilder();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user