From be348404564f2c83356df14eef9284e764086d96 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 9 May 2022 17:25:45 +0200 Subject: [PATCH 01/19] :green_heart: Add steamwarci.yml --- steamwarci.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 steamwarci.yml diff --git a/steamwarci.yml b/steamwarci.yml new file mode 100644 index 0000000..e6130a0 --- /dev/null +++ b/steamwarci.yml @@ -0,0 +1,6 @@ +build: + - "ln -s /home/gitea/lib" + - "cp ~/gradle.properties ." + - "chmod u+x build.gradle" + - "./gradlew buildProject" + - "./gradlew test" From 5e2d18a5b5d932947f571654d3cd2accb7d29a76 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 10 May 2022 09:09:15 +0200 Subject: [PATCH 02/19] Fix something so I can see the error --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 376b05d..7b5791a 100644 --- a/build.gradle +++ b/build.gradle @@ -87,7 +87,7 @@ task buildProject { description 'Build this project' group "Steamwar" - dependsOn build + dependsOn assemble } task finalizeProject { @@ -104,4 +104,4 @@ task finalizeProject { file(libs + "/" + uberJarName).renameTo(file(libs + "/" + jarName)) } } -build.finalizedBy(finalizeProject) \ No newline at end of file +assemble.finalizedBy(finalizeProject) \ No newline at end of file From 6113f0146d86a9474115fc8976eb01f7c0c1b80c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 10 May 2022 09:10:06 +0200 Subject: [PATCH 03/19] Fix something so I can see the error --- build.gradle | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7b5791a..235821e 100644 --- a/build.gradle +++ b/build.gradle @@ -104,4 +104,27 @@ task finalizeProject { file(libs + "/" + uberJarName).renameTo(file(libs + "/" + jarName)) } } -assemble.finalizedBy(finalizeProject) \ No newline at end of file +assemble.finalizedBy(finalizeProject) + +task testOutput { + description 'Print Test output' + group "Build" + + doLast { + for (def file : new File("${buildDir}/test-results/test/").listFiles()) { + if (file.isDirectory()) { + continue + } + def strings = file.readLines() + if (strings.get(1).contains("failures=\"0\"")) { + continue + } + println "Content ${file}:" + strings.each { + line -> println ": $line" + } + println "" + } + } +} +test.finalizedBy(testOutput) \ No newline at end of file From 0f636e589039d1cd59a43373d906d8a0d634a9eb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 10 May 2022 09:14:09 +0200 Subject: [PATCH 04/19] More tests --- src/de/steamwar/command/SubCommand.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/de/steamwar/command/SubCommand.java b/src/de/steamwar/command/SubCommand.java index 603e6d3..74d1a80 100644 --- a/src/de/steamwar/command/SubCommand.java +++ b/src/de/steamwar/command/SubCommand.java @@ -43,6 +43,7 @@ public class SubCommand { private CommandPart commandPart; SubCommand(AbstractSWCommand abstractSWCommand, Method method, String[] subCommand, Map> localTypeMapper, Map> localGuardChecker, boolean help, String[] description, boolean noTabComplete) { + System.out.println(method); this.abstractSWCommand = abstractSWCommand; this.method = method; this.subCommand = subCommand; From 5372781618ceab430dd56fceaec838ef5bca5ef1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 10 May 2022 09:19:30 +0200 Subject: [PATCH 05/19] More tests --- src/de/steamwar/command/AbstractSWCommand.java | 2 +- src/de/steamwar/command/SubCommand.java | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/command/AbstractSWCommand.java b/src/de/steamwar/command/AbstractSWCommand.java index fd371df..1cb830a 100644 --- a/src/de/steamwar/command/AbstractSWCommand.java +++ b/src/de/steamwar/command/AbstractSWCommand.java @@ -170,7 +170,7 @@ public abstract class AbstractSWCommand { if (compare != 0) { return compare; } else { - return Integer.compare(o1.comparableValue, o2.comparableValue); + return Double.compare(o1.comparableValue, o2.comparableValue); } }); commandHelpList.sort((o1, o2) -> { diff --git a/src/de/steamwar/command/SubCommand.java b/src/de/steamwar/command/SubCommand.java index 74d1a80..c928268 100644 --- a/src/de/steamwar/command/SubCommand.java +++ b/src/de/steamwar/command/SubCommand.java @@ -23,6 +23,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -30,6 +31,14 @@ import java.util.function.Predicate; public class SubCommand { + private static Map, Double> increment = new HashMap<>(); + static { + increment.put(double.class, 0.1); + increment.put(Double.class, 0.1); + increment.put(float.class, 0.1); + increment.put(Float.class, 0.1); + } + private AbstractSWCommand abstractSWCommand; Method method; String[] description; @@ -38,12 +47,11 @@ public class SubCommand { private Function senderFunction; AbstractGuardChecker guardChecker; boolean noTabComplete; - int comparableValue; + double comparableValue; private CommandPart commandPart; SubCommand(AbstractSWCommand abstractSWCommand, Method method, String[] subCommand, Map> localTypeMapper, Map> localGuardChecker, boolean help, String[] description, boolean noTabComplete) { - System.out.println(method); this.abstractSWCommand = abstractSWCommand; this.method = method; this.subCommand = subCommand; @@ -52,6 +60,9 @@ public class SubCommand { Parameter[] parameters = method.getParameters(); comparableValue = parameters[parameters.length - 1].isVarArgs() ? Integer.MAX_VALUE : -parameters.length; + for (Parameter parameter : parameters) { + comparableValue += increment.getOrDefault(parameter.getType(), 0.0); + } guardChecker = SWCommandUtils.getGuardChecker(parameters[0], localGuardChecker); From 0bd3f2bd88289038368e14862d6296c5021d6841 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 10 May 2022 09:22:31 +0200 Subject: [PATCH 06/19] Update some stuff --- build.gradle | 4 ++-- steamwarci.yml | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 235821e..392edc1 100644 --- a/build.gradle +++ b/build.gradle @@ -87,7 +87,7 @@ task buildProject { description 'Build this project' group "Steamwar" - dependsOn assemble + dependsOn build } task finalizeProject { @@ -104,7 +104,7 @@ task finalizeProject { file(libs + "/" + uberJarName).renameTo(file(libs + "/" + jarName)) } } -assemble.finalizedBy(finalizeProject) +build.finalizedBy(finalizeProject) task testOutput { description 'Print Test output' diff --git a/steamwarci.yml b/steamwarci.yml index e6130a0..73f8039 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -3,4 +3,3 @@ build: - "cp ~/gradle.properties ." - "chmod u+x build.gradle" - "./gradlew buildProject" - - "./gradlew test" From e091621fbdd479d7fdca78951ad2efdb4bc00810 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 10 May 2022 09:23:50 +0200 Subject: [PATCH 07/19] Fix CI --- steamwarci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/steamwarci.yml b/steamwarci.yml index 73f8039..4522945 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -3,3 +3,5 @@ build: - "cp ~/gradle.properties ." - "chmod u+x build.gradle" - "./gradlew buildProject" + +artifacts: [] \ No newline at end of file From 2437b5c0c56c170f9c4a836b2cdf4d3763be22fb Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 10 May 2022 09:25:05 +0200 Subject: [PATCH 08/19] =?UTF-8?q?=E2=80=9Esteamwarci.yml=E2=80=9C=20=C3=A4?= =?UTF-8?q?ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- steamwarci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steamwarci.yml b/steamwarci.yml index 4522945..974dc9c 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -4,4 +4,4 @@ build: - "chmod u+x build.gradle" - "./gradlew buildProject" -artifacts: [] \ No newline at end of file +artifacts: \ No newline at end of file From 2a2dbd9458f61987cfbd304051f96d7066c8d6cd Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 10 May 2022 09:26:01 +0200 Subject: [PATCH 09/19] Update some stuff --- src/de/steamwar/command/AbstractSWCommand.java | 2 +- src/de/steamwar/command/SubCommand.java | 14 +------------- steamwarci.yml | 2 ++ testsrc/de/steamwar/command/ArgumentCommand.java | 2 +- .../de/steamwar/command/ArgumentCommandTest.java | 2 +- 5 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/de/steamwar/command/AbstractSWCommand.java b/src/de/steamwar/command/AbstractSWCommand.java index 1cb830a..fd371df 100644 --- a/src/de/steamwar/command/AbstractSWCommand.java +++ b/src/de/steamwar/command/AbstractSWCommand.java @@ -170,7 +170,7 @@ public abstract class AbstractSWCommand { if (compare != 0) { return compare; } else { - return Double.compare(o1.comparableValue, o2.comparableValue); + return Integer.compare(o1.comparableValue, o2.comparableValue); } }); commandHelpList.sort((o1, o2) -> { diff --git a/src/de/steamwar/command/SubCommand.java b/src/de/steamwar/command/SubCommand.java index c928268..603e6d3 100644 --- a/src/de/steamwar/command/SubCommand.java +++ b/src/de/steamwar/command/SubCommand.java @@ -23,7 +23,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -31,14 +30,6 @@ import java.util.function.Predicate; public class SubCommand { - private static Map, Double> increment = new HashMap<>(); - static { - increment.put(double.class, 0.1); - increment.put(Double.class, 0.1); - increment.put(float.class, 0.1); - increment.put(Float.class, 0.1); - } - private AbstractSWCommand abstractSWCommand; Method method; String[] description; @@ -47,7 +38,7 @@ public class SubCommand { private Function senderFunction; AbstractGuardChecker guardChecker; boolean noTabComplete; - double comparableValue; + int comparableValue; private CommandPart commandPart; @@ -60,9 +51,6 @@ public class SubCommand { Parameter[] parameters = method.getParameters(); comparableValue = parameters[parameters.length - 1].isVarArgs() ? Integer.MAX_VALUE : -parameters.length; - for (Parameter parameter : parameters) { - comparableValue += increment.getOrDefault(parameter.getType(), 0.0); - } guardChecker = SWCommandUtils.getGuardChecker(parameters[0], localGuardChecker); diff --git a/steamwarci.yml b/steamwarci.yml index 73f8039..08bed06 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -3,3 +3,5 @@ build: - "cp ~/gradle.properties ." - "chmod u+x build.gradle" - "./gradlew buildProject" + +artifacts: diff --git a/testsrc/de/steamwar/command/ArgumentCommand.java b/testsrc/de/steamwar/command/ArgumentCommand.java index b4ce500..a107270 100644 --- a/testsrc/de/steamwar/command/ArgumentCommand.java +++ b/testsrc/de/steamwar/command/ArgumentCommand.java @@ -39,7 +39,7 @@ public class ArgumentCommand extends TestSWCommand { } @Register - public void argument(String sender, double d, double d2) { + public void argument(String sender, double d, double d2, double d3, double d4) { throw new ExecutionIdentifier("RunArgument with Double"); } diff --git a/testsrc/de/steamwar/command/ArgumentCommandTest.java b/testsrc/de/steamwar/command/ArgumentCommandTest.java index c546127..e57edd0 100644 --- a/testsrc/de/steamwar/command/ArgumentCommandTest.java +++ b/testsrc/de/steamwar/command/ArgumentCommandTest.java @@ -63,7 +63,7 @@ public class ArgumentCommandTest { public void testDouble() { ArgumentCommand cmd = new ArgumentCommand(); try { - cmd.execute("test", "", new String[]{"0.0", "0.0"}); + cmd.execute("test", "", new String[]{"0.0", "0.0", "0.0", "0.0"}); } catch (Exception e) { assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with Double"); } From 2d52bcbc60168e0e98219a32b4e7dfdc3d7ff485 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 10 May 2022 09:29:16 +0200 Subject: [PATCH 10/19] =?UTF-8?q?=E2=80=9Esteamwarci.yml=E2=80=9C=20=C3=A4?= =?UTF-8?q?ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- steamwarci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/steamwarci.yml b/steamwarci.yml index 08bed06..73f8039 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -3,5 +3,3 @@ build: - "cp ~/gradle.properties ." - "chmod u+x build.gradle" - "./gradlew buildProject" - -artifacts: From fa68ad9cfcee0ebd8db9b394d677b67c7f014825 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 10 May 2022 10:03:47 +0200 Subject: [PATCH 11/19] Fix stuff --- build.gradle | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/build.gradle b/build.gradle index 392edc1..41ba86c 100644 --- a/build.gradle +++ b/build.gradle @@ -90,22 +90,6 @@ task buildProject { dependsOn build } -task finalizeProject { - description 'Finalize this project' - group "Steamwar" - - doLast { - if ("${buildDir}" == null) { - return - } - delete fileTree("${libs}").matching { - exclude("${uberJarName}") - } - file(libs + "/" + uberJarName).renameTo(file(libs + "/" + jarName)) - } -} -build.finalizedBy(finalizeProject) - task testOutput { description 'Print Test output' group "Build" From f488c90fd0efe138d0b9cddba3c32134ec7f2c65 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 10 May 2022 10:07:57 +0200 Subject: [PATCH 12/19] Fix stuff --- src/de/steamwar/command/AbstractSWCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/command/AbstractSWCommand.java b/src/de/steamwar/command/AbstractSWCommand.java index fd371df..e1d953e 100644 --- a/src/de/steamwar/command/AbstractSWCommand.java +++ b/src/de/steamwar/command/AbstractSWCommand.java @@ -43,7 +43,7 @@ public abstract class AbstractSWCommand { this(clazz, command, new String[0]); } - protected AbstractSWCommand(Class clazz, String command, String[] aliases) { + protected AbstractSWCommand(Class clazz, String command, String... aliases) { this.clazz = clazz; createAndSafeCommand(command, aliases); unregister(); From 07e87b0c0ed2f5ddfcd9208b6a01f2b5611cd0c9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 10 May 2022 10:16:02 +0200 Subject: [PATCH 13/19] Fix stuff --- src/de/steamwar/command/SWCommandUtils.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/de/steamwar/command/SWCommandUtils.java b/src/de/steamwar/command/SWCommandUtils.java index 067bc35..e038e23 100644 --- a/src/de/steamwar/command/SWCommandUtils.java +++ b/src/de/steamwar/command/SWCommandUtils.java @@ -192,19 +192,19 @@ public class SWCommandUtils { GUARD_FUNCTIONS.putIfAbsent(name, guardChecker); } - public static AbstractTypeMapper createMapper(String... values) { + public static , K> T createMapper(String... values) { List strings = Arrays.asList(values); return createMapper((s) -> strings.contains(s) ? s : null, s -> strings); } - public static AbstractTypeMapper createMapper(Function mapper, Function> tabCompleter) { + public static , K, V> T createMapper(Function mapper, Function> tabCompleter) { return createMapper(mapper, (commandSender, s) -> tabCompleter.apply(s)); } - public static AbstractTypeMapper createMapper(Function mapper, BiFunction> tabCompleter) { - return new AbstractTypeMapper() { + public static , K, V> T createMapper(Function mapper, BiFunction> tabCompleter) { + return (T) new AbstractTypeMapper() { @Override - public T map(K commandSender, String[] previousArguments, String s) { + public V map(K commandSender, String[] previousArguments, String s) { return mapper.apply(s); } @@ -215,12 +215,12 @@ public class SWCommandUtils { }; } - public static AbstractTypeMapper> createEnumMapper(Class> enumClass) { + public static >, K> T createEnumMapper(Class> enumClass) { Map> enumMap = new HashMap<>(); for (Enum e : enumClass.getEnumConstants()) { enumMap.put(e.name(), e); } - return new AbstractTypeMapper>() { + return (T) new AbstractTypeMapper>() { @Override public Enum map(Object commandSender, String[] previousArguments, String s) { return enumMap.get(s); From 128aca96975b22a92743334d5c7392671bfa0a9d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 10 May 2022 10:48:39 +0200 Subject: [PATCH 14/19] Fix stuff --- src/de/steamwar/command/AbstractSWCommand.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/command/AbstractSWCommand.java b/src/de/steamwar/command/AbstractSWCommand.java index e1d953e..7228084 100644 --- a/src/de/steamwar/command/AbstractSWCommand.java +++ b/src/de/steamwar/command/AbstractSWCommand.java @@ -127,7 +127,8 @@ public abstract class AbstractSWCommand { SWCommandUtils.getGUARD_FUNCTIONS().putIfAbsent(anno.value().getTypeName(), guardChecker); } }); - + } + for (Method method : methods) { add(Register.class, method, i -> i > 0, true, null, (anno, parameters) -> { if (!anno.help()) return; if (parameters.length != 2) { @@ -142,8 +143,7 @@ public abstract class AbstractSWCommand { } commandHelpList.add(new SubCommand(this, method, anno.value(), new HashMap<>(), localGuardChecker, true, null, anno.noTabComplete())); }); - } - for (Method method : methods) { + add(Register.class, method, i -> i > 0, true, null, (anno, parameters) -> { if (anno.help()) return; for (int i = 1; i < parameters.length; i++) { @@ -199,7 +199,7 @@ public abstract class AbstractSWCommand { commandSystemWarning(() -> "The method '" + method.toString() + "' is lacking the first parameter of type '" + clazz.getTypeName() + "'"); return; } - if (returnType != null && !method.getReturnType().isAssignableFrom(returnType)) { + if (returnType != null && !returnType.isAssignableFrom(method.getReturnType())) { commandSystemWarning(() -> "The method '" + method.toString() + "' is lacking the desired return type '" + returnType.getTypeName() + "'"); return; } From 0f03b57e437c1d843816b7202d95b79ff0a8d2df Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 10 May 2022 10:57:39 +0200 Subject: [PATCH 15/19] Fix stuff --- .../steamwar/command/AbstractSWCommand.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/de/steamwar/command/AbstractSWCommand.java b/src/de/steamwar/command/AbstractSWCommand.java index 7228084..d654df7 100644 --- a/src/de/steamwar/command/AbstractSWCommand.java +++ b/src/de/steamwar/command/AbstractSWCommand.java @@ -141,7 +141,7 @@ public abstract class AbstractSWCommand { commandSystemWarning(() -> "The method '" + method.toString() + "' is lacking the varArgs parameters of type '" + String.class.getTypeName() + "' as last Argument"); return; } - commandHelpList.add(new SubCommand(this, method, anno.value(), new HashMap<>(), localGuardChecker, true, null, anno.noTabComplete())); + commandHelpList.add(new SubCommand<>(this, method, anno.value(), new HashMap<>(), localGuardChecker, true, null, anno.noTabComplete())); }); add(Register.class, method, i -> i > 0, true, null, (anno, parameters) -> { @@ -162,27 +162,27 @@ public abstract class AbstractSWCommand { return; } } - commandList.add(new SubCommand(this, method, anno.value(), localTypeMapper, localGuardChecker, false, anno.description(), anno.noTabComplete())); - }); - - this.commandList.sort((o1, o2) -> { - int compare = Integer.compare(-o1.subCommand.length, -o2.subCommand.length); - if (compare != 0) { - return compare; - } else { - return Integer.compare(o1.comparableValue, o2.comparableValue); - } - }); - commandHelpList.sort((o1, o2) -> { - int compare = Integer.compare(-o1.subCommand.length, -o2.subCommand.length); - if (compare != 0) { - return compare; - } else { - return Integer.compare(o1.method.getDeclaringClass() == AbstractSWCommand.class ? 1 : 0, - o2.method.getDeclaringClass() == AbstractSWCommand.class ? 1 : 0); - } + commandList.add(new SubCommand<>(this, method, anno.value(), localTypeMapper, localGuardChecker, false, anno.description(), anno.noTabComplete())); }); } + + this.commandList.sort((o1, o2) -> { + int compare = Integer.compare(-o1.subCommand.length, -o2.subCommand.length); + if (compare != 0) { + return compare; + } else { + return Integer.compare(o1.comparableValue, o2.comparableValue); + } + }); + commandHelpList.sort((o1, o2) -> { + int compare = Integer.compare(-o1.subCommand.length, -o2.subCommand.length); + if (compare != 0) { + return compare; + } else { + return Integer.compare(o1.method.getDeclaringClass() == AbstractSWCommand.class ? 1 : 0, + o2.method.getDeclaringClass() == AbstractSWCommand.class ? 1 : 0); + } + }); initialized = true; } @@ -238,7 +238,7 @@ public abstract class AbstractSWCommand { private List methods() { List methods = new ArrayList<>(); Class current = getClass(); - while (current.getSuperclass() != AbstractSWCommand.class) { + while (current != AbstractSWCommand.class) { methods.addAll(Arrays.asList(current.getDeclaredMethods())); current = current.getSuperclass(); } From 96a5ec6b2fd249ec8105470775e78b92596ad9be Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 30 May 2022 14:32:38 +0200 Subject: [PATCH 16/19] Fix enum mapper --- src/de/steamwar/command/SWCommandUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/command/SWCommandUtils.java b/src/de/steamwar/command/SWCommandUtils.java index e038e23..73468fa 100644 --- a/src/de/steamwar/command/SWCommandUtils.java +++ b/src/de/steamwar/command/SWCommandUtils.java @@ -218,12 +218,12 @@ public class SWCommandUtils { public static >, K> T createEnumMapper(Class> enumClass) { Map> enumMap = new HashMap<>(); for (Enum e : enumClass.getEnumConstants()) { - enumMap.put(e.name(), e); + enumMap.put(e.name().toLowerCase(), e); } return (T) new AbstractTypeMapper>() { @Override public Enum map(Object commandSender, String[] previousArguments, String s) { - return enumMap.get(s); + return enumMap.get(s.toLowerCase()); } @Override From 0674c951aa70482bfb9238a5b87fc5ce9b2ca078 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 30 May 2022 14:52:21 +0200 Subject: [PATCH 17/19] Fix SWCommandUtils Add SWTypeMapperCreator --- src/de/steamwar/command/SWCommandUtils.java | 36 ++++++------------- .../steamwar/command/SWTypeMapperCreator.java | 28 +++++++++++++++ 2 files changed, 38 insertions(+), 26 deletions(-) create mode 100644 src/de/steamwar/command/SWTypeMapperCreator.java diff --git a/src/de/steamwar/command/SWCommandUtils.java b/src/de/steamwar/command/SWCommandUtils.java index 73468fa..331b9f9 100644 --- a/src/de/steamwar/command/SWCommandUtils.java +++ b/src/de/steamwar/command/SWCommandUtils.java @@ -38,7 +38,11 @@ public class SWCommandUtils { @Getter private final Map> GUARD_FUNCTIONS = new HashMap<>(); - static { + private SWTypeMapperCreator swTypeMapperCreator; + + public static , K, V> void init(SWTypeMapperCreator swTypeMapperCreator) { + SWCommandUtils.swTypeMapperCreator = swTypeMapperCreator; + addMapper(boolean.class, Boolean.class, createMapper(s -> { if (s.equalsIgnoreCase("true")) return true; if (s.equalsIgnoreCase("false")) return false; @@ -197,22 +201,12 @@ public class SWCommandUtils { return createMapper((s) -> strings.contains(s) ? s : null, s -> strings); } - public static , K, V> T createMapper(Function mapper, Function> tabCompleter) { + public static , K, V> T createMapper(Function mapper, Function> tabCompleter) { return createMapper(mapper, (commandSender, s) -> tabCompleter.apply(s)); } - public static , K, V> T createMapper(Function mapper, BiFunction> tabCompleter) { - return (T) new AbstractTypeMapper() { - @Override - public V map(K commandSender, String[] previousArguments, String s) { - return mapper.apply(s); - } - - @Override - public List tabCompletes(K commandSender, String[] previous, String s) { - return tabCompleter.apply(commandSender, s); - } - }; + public static , K, V> T createMapper(Function mapper, BiFunction> tabCompleter) { + return (T) swTypeMapperCreator.createTypeMapper(mapper, tabCompleter); } public static >, K> T createEnumMapper(Class> enumClass) { @@ -220,17 +214,7 @@ public class SWCommandUtils { for (Enum e : enumClass.getEnumConstants()) { enumMap.put(e.name().toLowerCase(), e); } - return (T) new AbstractTypeMapper>() { - @Override - public Enum map(Object commandSender, String[] previousArguments, String s) { - return enumMap.get(s.toLowerCase()); - } - - @Override - public Collection tabCompletes(Object commandSender, String[] previousArguments, String s) { - return enumMap.keySet(); - } - }; + return createMapper(s -> enumMap.get(s.toLowerCase()), (k, s) -> enumMap.keySet()); } private static Function numberMapper(Function mapper) { @@ -249,7 +233,7 @@ public class SWCommandUtils { }; } - private static Function> numberCompleter(Function mapper) { + private static Function> numberCompleter(Function mapper) { return s -> numberMapper(mapper).apply(s) != null ? Collections.singletonList(s) : Collections.emptyList(); diff --git a/src/de/steamwar/command/SWTypeMapperCreator.java b/src/de/steamwar/command/SWTypeMapperCreator.java new file mode 100644 index 0000000..33c5dcb --- /dev/null +++ b/src/de/steamwar/command/SWTypeMapperCreator.java @@ -0,0 +1,28 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.command; + +import java.util.List; +import java.util.function.BiFunction; +import java.util.function.Function; + +public interface SWTypeMapperCreator, K, V> { + T createTypeMapper(Function mapper, BiFunction> tabCompleter); +} From b0d74ed5a347ef97e8b418deb374304f0d3da593 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 30 May 2022 14:59:00 +0200 Subject: [PATCH 18/19] Fix SWCommandUtils --- src/de/steamwar/command/SWCommandUtils.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/command/SWCommandUtils.java b/src/de/steamwar/command/SWCommandUtils.java index 331b9f9..6e486b1 100644 --- a/src/de/steamwar/command/SWCommandUtils.java +++ b/src/de/steamwar/command/SWCommandUtils.java @@ -38,11 +38,19 @@ public class SWCommandUtils { @Getter private final Map> GUARD_FUNCTIONS = new HashMap<>(); - private SWTypeMapperCreator swTypeMapperCreator; + private SWTypeMapperCreator swTypeMapperCreator = (mapper, tabCompleter) -> new AbstractTypeMapper() { + @Override + public Object map(Object sender, String[] previousArguments, String s) { + return mapper.apply(s); + } - public static , K, V> void init(SWTypeMapperCreator swTypeMapperCreator) { - SWCommandUtils.swTypeMapperCreator = swTypeMapperCreator; + @Override + public Collection tabCompletes(Object sender, String[] previousArguments, String s) { + return tabCompleter.apply(sender, s); + } + }; + static { addMapper(boolean.class, Boolean.class, createMapper(s -> { if (s.equalsIgnoreCase("true")) return true; if (s.equalsIgnoreCase("false")) return false; @@ -55,6 +63,10 @@ public class SWCommandUtils { MAPPER_FUNCTIONS.put(String.class.getTypeName(), createMapper(s -> s, Collections::singletonList)); } + public static , K, V> void init(SWTypeMapperCreator swTypeMapperCreator) { + SWCommandUtils.swTypeMapperCreator = swTypeMapperCreator; + } + private static void addMapper(Class clazz, Class alternativeClazz, AbstractTypeMapper mapper) { MAPPER_FUNCTIONS.put(clazz.getTypeName(), mapper); MAPPER_FUNCTIONS.put(alternativeClazz.getTypeName(), mapper); From 919c4d525ea39756b24bd961bb72d8d58bdd5bd4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 30 May 2022 15:04:51 +0200 Subject: [PATCH 19/19] Fix SWCommandUtils --- src/de/steamwar/command/SWCommandUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/command/SWCommandUtils.java b/src/de/steamwar/command/SWCommandUtils.java index 6e486b1..aaf0c7a 100644 --- a/src/de/steamwar/command/SWCommandUtils.java +++ b/src/de/steamwar/command/SWCommandUtils.java @@ -46,7 +46,7 @@ public class SWCommandUtils { @Override public Collection tabCompletes(Object sender, String[] previousArguments, String s) { - return tabCompleter.apply(sender, s); + return ((BiFunction>) tabCompleter).apply(sender, s); } };