Fixed issues with suggesting redirects
This commit is contained in:
@@ -177,11 +177,11 @@ public class CommandDispatcher<S> {
|
||||
}
|
||||
|
||||
context.withCommand(child.getCommand());
|
||||
if (reader.canRead(2)) {
|
||||
if (reader.canRead(child.getRedirect() == null ? 2 : 1)) {
|
||||
reader.skip();
|
||||
if (child.getRedirect() != null) {
|
||||
final CommandContextBuilder<S> childContext = new CommandContextBuilder<>(this, source, reader.getCursor());
|
||||
childContext.withNode(child.getRedirect(), new StringRange(reader.getCursor(), reader.getCursor()));
|
||||
childContext.withNode(child.getRedirect(), new StringRange(cursor, reader.getCursor() - 1));
|
||||
final ParseResults<S> parse = parseNodes(child.getRedirect(), reader, childContext);
|
||||
context.withChild(parse.getContext());
|
||||
return new ParseResults<>(context, parse.getReader(), parse.getExceptions());
|
||||
@@ -311,7 +311,8 @@ public class CommandDispatcher<S> {
|
||||
}
|
||||
|
||||
public CompletableFuture<CommandSuggestions> getCompletionSuggestions(final ParseResults<S> parse) {
|
||||
final CommandContextBuilder<S> context = parse.getContext();
|
||||
final CommandContextBuilder<S> rootContext = parse.getContext();
|
||||
final CommandContextBuilder<S> context = rootContext.getLastChild();
|
||||
final CommandNode<S> parent;
|
||||
final int start;
|
||||
|
||||
@@ -326,6 +327,10 @@ public class CommandDispatcher<S> {
|
||||
final Map.Entry<CommandNode<S>, StringRange> entry = Iterables.get(context.getNodes().entrySet(), context.getNodes().size() - 2);
|
||||
parent = entry.getKey();
|
||||
start = entry.getValue().getEnd() + 1;
|
||||
} else if (rootContext != context && context.getNodes().size() > 0) {
|
||||
final Map.Entry<CommandNode<S>, StringRange> entry = Iterables.getLast(context.getNodes().entrySet());
|
||||
parent = entry.getKey();
|
||||
start = entry.getValue().getEnd() + 1;
|
||||
} else {
|
||||
parent = root;
|
||||
start = 0;
|
||||
|
||||
@@ -30,6 +30,14 @@ public class CommandContext<S> {
|
||||
return child;
|
||||
}
|
||||
|
||||
public CommandContext<S> getLastChild() {
|
||||
CommandContext<S> result = this;
|
||||
while (result.getChild() != null) {
|
||||
result = result.getChild();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Command<S> getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
@@ -70,6 +70,14 @@ public class CommandContextBuilder<S> {
|
||||
return child;
|
||||
}
|
||||
|
||||
public CommandContextBuilder<S> getLastChild() {
|
||||
CommandContextBuilder<S> result = this;
|
||||
while (result.getChild() != null) {
|
||||
result = result.getChild();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Command<S> getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
@@ -50,9 +50,9 @@ public class LiteralCommandNode<S> extends CommandNode<S> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Collection<String>> listSuggestions(CommandContext<S> context, final String command) {
|
||||
public CompletableFuture<Collection<String>> listSuggestions(final CommandContext<S> context, final String command) {
|
||||
if (literal.toLowerCase().startsWith(command.toLowerCase())) {
|
||||
return CompletableFuture.completedFuture(Collections.singleton(literal));
|
||||
return CompletableFuture.completedFuture(Collections.singleton(literal + " "));
|
||||
} else {
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user