From 14b5d9fc3c278995ee49c993dfaf6bb1f4630796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Thu, 17 Sep 2020 09:50:36 +0200 Subject: [PATCH] Command suggestion improvements --- .../com/intellectualsites/commands/CommandTree.java | 5 +++-- .../commands/CommandSuggestionsTest.java | 12 +++++++++--- .../intellectualsites/commands/CommandTreeTest.java | 2 +- .../com/intellectualsites/commands/BukkitTest.java | 1 + 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/CommandTree.java b/cloud-core/src/main/java/com/intellectualsites/commands/CommandTree.java index d91a6ba6..41d5c8e9 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/CommandTree.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/CommandTree.java @@ -280,7 +280,8 @@ public final class CommandTree { final Node> 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 { } } /* 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>> childIterator = root.getChildren().iterator(); diff --git a/cloud-core/src/test/java/com/intellectualsites/commands/CommandSuggestionsTest.java b/cloud-core/src/test/java/com/intellectualsites/commands/CommandSuggestionsTest.java index d25e261b..ed664820 100644 --- a/cloud-core/src/test/java/com/intellectualsites/commands/CommandSuggestionsTest.java +++ b/cloud-core/src/test/java/com/intellectualsites/commands/CommandSuggestionsTest.java @@ -58,20 +58,26 @@ public class CommandSuggestionsTest { void testSimple() { final String input = "test"; final List suggestions = manager.suggest(new TestCommandSender(), input); - Assertions.assertEquals(Arrays.asList("one", "two", "var"), suggestions); + Assertions.assertTrue(suggestions.isEmpty()); + final String input2 = "test "; + final List suggestions2 = manager.suggest(new TestCommandSender(), input2); + Assertions.assertEquals(Arrays.asList("one", "two","var"), suggestions2); } @Test void testVar() { final String input = "test var"; final List 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 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 suggestions3 = manager.suggest(new TestCommandSender(), input3); Assertions.assertEquals(Collections.singletonList("foo"), suggestions3); + final String input4 = "test var one "; + final List suggestions4 = manager.suggest(new TestCommandSender(), input4); + Assertions.assertEquals(Arrays.asList("foo", "bar"), suggestions4); } @Test diff --git a/cloud-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java b/cloud-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java index ef2ab441..e02b05cc 100644 --- a/cloud-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java +++ b/cloud-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java @@ -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 diff --git a/cloud-minecraft/cloud-bukkit-test/src/main/java/com/intellectualsites/commands/BukkitTest.java b/cloud-minecraft/cloud-bukkit-test/src/main/java/com/intellectualsites/commands/BukkitTest.java index d3a79853..6a25e4bf 100644 --- a/cloud-minecraft/cloud-bukkit-test/src/main/java/com/intellectualsites/commands/BukkitTest.java +++ b/cloud-minecraft/cloud-bukkit-test/src/main/java/com/intellectualsites/commands/BukkitTest.java @@ -146,6 +146,7 @@ public final class BukkitTest extends JavaPlugin { .component(IntegerComponent.required("int")) .component(BooleanComponent.required("bool")) .component(StringComponent.required("string")) + .handler(c -> c.getSender().sendMessage("Executed the command")) .build()); } catch (final Exception e) { e.printStackTrace();