From ae26f2837d5dcb043c48627ce92ea160b5f1f2bd Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 25 Mar 2021 14:21:36 +0100 Subject: [PATCH] Fix SWCommand with Mapper Simplify SWCommand registering mapper and commands --- .../src/de/steamwar/command/SWCommand.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index de49a86..c765932 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -73,15 +73,15 @@ public abstract class SWCommand { } }); + Set commandMethods = new HashSet<>(); for (Method method : getClass().getDeclaredMethods()) { addMapper(method); + addCommand(method, commandMethods); } - for (Method method : getClass().getDeclaredMethods()) { - addCommand(method); - } + commandMethods.forEach(method -> commandSet.add(new SubCommand(this, method))); } - private void addCommand(Method method) { + private void addCommand(Method method, Set commandMethods) { Register register = method.getDeclaredAnnotation(Register.class); Mapper methodMapper = method.getDeclaredAnnotation(Mapper.class); if (register == null || methodMapper != null) { @@ -101,17 +101,17 @@ public abstract class SWCommand { if (parameter.isVarArgs() && i == parameters.length - 1) { clazz = parameter.getType().getComponentType(); } - if (clazz.isEnum()) { + Mapper mapper = parameter.getAnnotation(Mapper.class); + if (clazz.isEnum() && mapper == null) { continue; } String name = clazz.getTypeName(); - Mapper mapper = parameter.getAnnotation(Mapper.class); if (mapper != null) { name = mapper.value(); } if (!SWCommandUtils.MAPPER_FUNCTIONS.containsKey(name)) return; } - commandSet.add(new SubCommand(this, method)); + commandMethods.add(method); } private void addMapper(Method method) {