diff --git a/SpigotCore_Main/build.gradle b/SpigotCore_Main/build.gradle index faeb028..9d129c5 100644 --- a/SpigotCore_Main/build.gradle +++ b/SpigotCore_Main/build.gradle @@ -27,8 +27,8 @@ version '1.0' compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = 1.11 +targetCompatibility = 1.11 sourceSets { main { diff --git a/SpigotCore_Main/src/de/steamwar/command/CommandPart.java b/SpigotCore_Main/src/de/steamwar/command/CommandPart.java index 65ff631..d0e7fb7 100644 --- a/SpigotCore_Main/src/de/steamwar/command/CommandPart.java +++ b/SpigotCore_Main/src/de/steamwar/command/CommandPart.java @@ -170,6 +170,10 @@ public class CommandPart { CheckArgumentResult checkArgumentResult = checkArgument(GuardCheckType.TAB_COMPLETE, commandSender, args, startIndex); if (checkArgumentResult.success && next != null) { next.generateTabComplete(current, commandSender, args, startIndex + 1); + return; + } + if (optional != null && next != null) { + next.generateTabComplete(current, commandSender, args, startIndex); } return; } diff --git a/SpigotCore_Main/testsrc/de/steamwar/command/SimpleCommandPartTest.java b/SpigotCore_Main/testsrc/de/steamwar/command/SimpleCommandPartTest.java index a9474a0..08dccf7 100644 --- a/SpigotCore_Main/testsrc/de/steamwar/command/SimpleCommandPartTest.java +++ b/SpigotCore_Main/testsrc/de/steamwar/command/SimpleCommandPartTest.java @@ -40,6 +40,8 @@ public class SimpleCommandPartTest { private CommandPart optionalCommandPart; + private CommandPart optionalCommandPartMultipleNext; + @Before public void setUp() throws Exception { stringCommandPart = new CommandPart(SWCommandUtils.createMapper("hello", "world"), null, null, null, GuardCheckType.COMMAND); @@ -54,6 +56,11 @@ public class SimpleCommandPartTest { optionalCommandPart = new CommandPart(SWCommandUtils.createMapper("hello", "world"), null, null, "hello", GuardCheckType.COMMAND); optionalCommandPart.setNext(new CommandPart(SWCommandUtils.createMapper("hello2", "world2"), null, null, null, GuardCheckType.COMMAND)); + + optionalCommandPartMultipleNext = new CommandPart(SWCommandUtils.createMapper("hello", "world"), null, null, "hello", GuardCheckType.COMMAND); + CommandPart next = new CommandPart(SWCommandUtils.createMapper("hello2", "world2"), null, null, null, GuardCheckType.COMMAND); + next.setNext(new CommandPart(SWCommandUtils.createMapper("hello3", "world3"), null, null, null, GuardCheckType.COMMAND)); + optionalCommandPartMultipleNext.setNext(next); } @Test @@ -240,4 +247,43 @@ public class SimpleCommandPartTest { assertThat(argumentArray.get(0), is("world")); assertThat(argumentArray.get(1), is("hello2")); } + + @Test + public void testOptionalCommandPartExecutionMultipleNext() { + List argumentArray = new ArrayList<>(); + optionalCommandPartMultipleNext.generateArgumentArray(argumentArray, new TestCommandSender(), new String[]{"world", "hello2", "hello3"}, 0); + assertThat(argumentArray.size(), is(3)); + assertThat(argumentArray.get(0), is("world")); + assertThat(argumentArray.get(1), is("hello2")); + assertThat(argumentArray.get(2), is("hello3")); + } + + @Test + public void testOptionalCommandPartExecutionMultipleTabComplete() { + List tabCompletes = new ArrayList<>(); + optionalCommandPartMultipleNext.generateTabComplete(tabCompletes, new TestCommandSender(), new String[]{""}, 0); + assertThat(tabCompletes.size(), is(4)); + assertThat(tabCompletes.get(0), is("hello")); + assertThat(tabCompletes.get(1), is("world")); + assertThat(tabCompletes.get(2), is("hello2")); + assertThat(tabCompletes.get(3), is("world2")); + + tabCompletes = new ArrayList<>(); + optionalCommandPartMultipleNext.generateTabComplete(tabCompletes, new TestCommandSender(), new String[]{"hello", ""}, 0); + assertThat(tabCompletes.size(), is(2)); + assertThat(tabCompletes.get(0), is("hello2")); + assertThat(tabCompletes.get(1), is("world2")); + + tabCompletes = new ArrayList<>(); + optionalCommandPartMultipleNext.generateTabComplete(tabCompletes, new TestCommandSender(), new String[]{"hello", "world2", ""}, 0); + assertThat(tabCompletes.size(), is(2)); + assertThat(tabCompletes.get(0), is("hello3")); + assertThat(tabCompletes.get(1), is("world3")); + + tabCompletes = new ArrayList<>(); + optionalCommandPartMultipleNext.generateTabComplete(tabCompletes, new TestCommandSender(), new String[]{"world2", ""}, 0); + assertThat(tabCompletes.size(), is(2)); + assertThat(tabCompletes.get(0), is("hello3")); + assertThat(tabCompletes.get(1), is("world3")); + } } diff --git a/build.gradle b/build.gradle index 52eae83..a228224 100644 --- a/build.gradle +++ b/build.gradle @@ -61,8 +61,8 @@ ext { compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = 1.11 +targetCompatibility = 1.11 mainClassName = ''