From 64c8d910c170a71903e50039634ecfe9bae97753 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 9 Dec 2021 23:18:32 +0100 Subject: [PATCH] Fix SWCommandUtils.generateCommandPart --- .../de/steamwar/command/SWCommandUtils.java | 42 ++----------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index 8e43884..c9b7f43 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -151,8 +151,8 @@ public class SWCommandUtils { clazz = clazz.getComponentType(); } - SWCommand.ClassMapper classMapper = clazz.getAnnotation(SWCommand.ClassMapper.class); - SWCommand.Mapper mapper = clazz.getAnnotation(SWCommand.Mapper.class); + SWCommand.ClassMapper classMapper = parameter.getAnnotation(SWCommand.ClassMapper.class); + SWCommand.Mapper mapper = parameter.getAnnotation(SWCommand.Mapper.class); if (clazz.isEnum() && classMapper == null && mapper == null && !MAPPER_FUNCTIONS.containsKey(clazz.getTypeName()) && !localTypeMapper.containsKey(clazz.getTypeName())) { return createEnumMapper((Class>) clazz); } @@ -181,7 +181,7 @@ public class SWCommandUtils { clazz = clazz.getComponentType(); } - SWCommand.ClassGuard classGuard = clazz.getAnnotation(SWCommand.ClassGuard.class); + SWCommand.ClassGuard classGuard = parameter.getAnnotation(SWCommand.ClassGuard.class); if (classGuard != null) { if (classGuard.value() != null) { return getGuardChecker(classGuard.value().getTypeName(), localGuardChecker); @@ -189,7 +189,7 @@ public class SWCommandUtils { return getGuardChecker(clazz.getTypeName(), localGuardChecker); } - SWCommand.Guard guard = clazz.getAnnotation(SWCommand.Guard.class); + SWCommand.Guard guard = parameter.getAnnotation(SWCommand.Guard.class); if (guard != null) { if (guard.value() != null) { return getGuardChecker(guard.value(), localGuardChecker); @@ -207,40 +207,6 @@ public class SWCommandUtils { return guardChecker; } - static Object[] generateArgumentArray(CommandSender commandSender, TypeMapper[] parameters, GuardChecker[] guards, String[] args, Class varArgType, String[] subCommand) throws CommandParseException { - Object[] arguments = new Object[parameters.length + 1]; - int index = 0; - while (index < subCommand.length) { - if (!args[index].equalsIgnoreCase(subCommand[index])) throw new CommandParseException(); - index++; - } - - int length = 0; - if (varArgType != null) { - length = args.length - parameters.length - subCommand.length + 1; - arguments[arguments.length - 1] = Array.newInstance(varArgType, length); - if (index > args.length - 1) return arguments; - } - - for (int i = 0; i < parameters.length - (varArgType != null ? 1 : 0); i++) { - arguments[i + 1] = parameters[i].map(commandSender, Arrays.copyOf(args, index), args[index]); - index++; - if (arguments[i + 1] == null) throw new CommandParseException(); - } - - if (varArgType != null) { - Object varArgument = arguments[arguments.length - 1]; - - for (int i = 0; i < length; i++) { - Object value = parameters[parameters.length - 1].map(commandSender, Arrays.copyOf(args, index), args[index]); - if (value == null) throw new CommandParseException(); - Array.set(varArgument, i, value); - index++; - } - } - return arguments; - } - public static void addMapper(Class clazz, TypeMapper mapper) { addMapper(clazz.getTypeName(), mapper); }