SteamWar/SpigotCore
Archiviert
13
0

Fix SWCommand with Mapper

Simplify SWCommand registering mapper and commands
Dieser Commit ist enthalten in:
yoyosource 2021-03-25 14:21:36 +01:00
Ursprung 57b5c2b81b
Commit ae26f2837d

Datei anzeigen

@ -73,15 +73,15 @@ public abstract class SWCommand {
}
});
Set<Method> 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<Method> 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) {