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);
|
final Node<CommandComponent<C, ?>> child = children.get(0);
|
||||||
if (child.getValue() != null) {
|
if (child.getValue() != null) {
|
||||||
if (commandQueue.isEmpty()) {
|
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) {
|
} else if (child.isLeaf() && commandQueue.size() < 2) {
|
||||||
return child.getValue().getParser().suggestions(commandContext, commandQueue.peek());
|
return child.getValue().getParser().suggestions(commandContext, commandQueue.peek());
|
||||||
} else if (child.isLeaf()) {
|
} 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 */
|
/* 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();
|
return Collections.emptyList();
|
||||||
} else {
|
} else {
|
||||||
final Iterator<Node<CommandComponent<C, ?>>> childIterator = root.getChildren().iterator();
|
final Iterator<Node<CommandComponent<C, ?>>> childIterator = root.getChildren().iterator();
|
||||||
|
|
|
||||||
|
|
@ -58,20 +58,26 @@ public class CommandSuggestionsTest {
|
||||||
void testSimple() {
|
void testSimple() {
|
||||||
final String input = "test";
|
final String input = "test";
|
||||||
final List<String> suggestions = manager.suggest(new TestCommandSender(), input);
|
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
|
@Test
|
||||||
void testVar() {
|
void testVar() {
|
||||||
final String input = "test var";
|
final String input = "test var";
|
||||||
final List<String> suggestions = manager.suggest(new TestCommandSender(), input);
|
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 String input2 = "test var one";
|
||||||
final List<String> suggestions2 = manager.suggest(new TestCommandSender(), input2);
|
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 String input3 = "test var one f";
|
||||||
final List<String> suggestions3 = manager.suggest(new TestCommandSender(), input3);
|
final List<String> suggestions3 = manager.suggest(new TestCommandSender(), input3);
|
||||||
Assertions.assertEquals(Collections.singletonList("foo"), suggestions3);
|
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
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -146,6 +146,7 @@ public final class BukkitTest extends JavaPlugin {
|
||||||
.component(IntegerComponent.required("int"))
|
.component(IntegerComponent.required("int"))
|
||||||
.component(BooleanComponent.required("bool"))
|
.component(BooleanComponent.required("bool"))
|
||||||
.component(StringComponent.required("string"))
|
.component(StringComponent.required("string"))
|
||||||
|
.handler(c -> c.getSender().sendMessage("Executed the command"))
|
||||||
.build());
|
.build());
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue