Command suggestion improvements
This commit is contained in:
parent
bc261676e7
commit
14b5d9fc3c
4 changed files with 14 additions and 6 deletions
|
|
@ -280,7 +280,8 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
|||
final Node<CommandComponent<C, ?>> child = children.get(0);
|
||||
if (child.getValue() != null) {
|
||||
if (commandQueue.isEmpty()) {
|
||||
return child.getValue().getParser().suggestions(commandContext, "");
|
||||
return Collections.emptyList();
|
||||
// return child.getValue().getParser().suggestions(commandContext, "");
|
||||
} else if (child.isLeaf() && commandQueue.size() < 2) {
|
||||
return child.getValue().getParser().suggestions(commandContext, commandQueue.peek());
|
||||
} else if (child.isLeaf()) {
|
||||
|
|
@ -296,7 +297,7 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
|||
}
|
||||
}
|
||||
/* There are 0 or more static components as children. No variable child components are present */
|
||||
if (children.isEmpty()) {
|
||||
if (children.isEmpty() || commandQueue.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
final Iterator<Node<CommandComponent<C, ?>>> childIterator = root.getChildren().iterator();
|
||||
|
|
|
|||
|
|
@ -58,20 +58,26 @@ public class CommandSuggestionsTest {
|
|||
void testSimple() {
|
||||
final String input = "test";
|
||||
final List<String> suggestions = manager.suggest(new TestCommandSender(), input);
|
||||
Assertions.assertEquals(Arrays.asList("one", "two", "var"), suggestions);
|
||||
Assertions.assertTrue(suggestions.isEmpty());
|
||||
final String input2 = "test ";
|
||||
final List<String> suggestions2 = manager.suggest(new TestCommandSender(), input2);
|
||||
Assertions.assertEquals(Arrays.asList("one", "two","var"), suggestions2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVar() {
|
||||
final String input = "test var";
|
||||
final List<String> suggestions = manager.suggest(new TestCommandSender(), input);
|
||||
Assertions.assertEquals(Arrays.asList("one", "two"), suggestions);
|
||||
Assertions.assertTrue(suggestions.isEmpty());
|
||||
final String input2 = "test var one";
|
||||
final List<String> suggestions2 = manager.suggest(new TestCommandSender(), input2);
|
||||
Assertions.assertEquals(Arrays.asList("foo", "bar"), suggestions2);
|
||||
Assertions.assertTrue(suggestions2.isEmpty());
|
||||
final String input3 = "test var one f";
|
||||
final List<String> suggestions3 = manager.suggest(new TestCommandSender(), input3);
|
||||
Assertions.assertEquals(Collections.singletonList("foo"), suggestions3);
|
||||
final String input4 = "test var one ";
|
||||
final List<String> suggestions4 = manager.suggest(new TestCommandSender(), input4);
|
||||
Assertions.assertEquals(Arrays.asList("foo", "bar"), suggestions4);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ class CommandTreeTest {
|
|||
void getSuggestions() {
|
||||
Assertions.assertFalse(
|
||||
commandManager.getCommandTree().getSuggestions(new CommandContext<>(new TestCommandSender()), new LinkedList<>(
|
||||
Collections.singletonList("test"))).isEmpty());
|
||||
Collections.singletonList("test "))).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue