SteamWar/SpigotCore
Archiviert
13
0

CMD #141

Zusammengeführt
YoyoNow hat 29 Commits von CMD nach master 2021-12-12 15:58:20 +01:00 zusammengeführt
Nur Änderungen aus Commit 64c8d910c1 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -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<Enum<?>>) 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 <T> void addMapper(Class<T> clazz, TypeMapper<T> mapper) {
addMapper(clazz.getTypeName(), mapper);
}