Fix SWCommand with Mapper
Simplify SWCommand registering mapper and commands
Dieser Commit ist enthalten in:
Ursprung
57b5c2b81b
Commit
ae26f2837d
@ -73,15 +73,15 @@ public abstract class SWCommand {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Set<Method> commandMethods = new HashSet<>();
|
||||||
for (Method method : getClass().getDeclaredMethods()) {
|
for (Method method : getClass().getDeclaredMethods()) {
|
||||||
addMapper(method);
|
addMapper(method);
|
||||||
|
addCommand(method, commandMethods);
|
||||||
}
|
}
|
||||||
for (Method method : getClass().getDeclaredMethods()) {
|
commandMethods.forEach(method -> commandSet.add(new SubCommand(this, method)));
|
||||||
addCommand(method);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addCommand(Method method) {
|
private void addCommand(Method method, Set<Method> commandMethods) {
|
||||||
Register register = method.getDeclaredAnnotation(Register.class);
|
Register register = method.getDeclaredAnnotation(Register.class);
|
||||||
Mapper methodMapper = method.getDeclaredAnnotation(Mapper.class);
|
Mapper methodMapper = method.getDeclaredAnnotation(Mapper.class);
|
||||||
if (register == null || methodMapper != null) {
|
if (register == null || methodMapper != null) {
|
||||||
@ -101,17 +101,17 @@ public abstract class SWCommand {
|
|||||||
if (parameter.isVarArgs() && i == parameters.length - 1) {
|
if (parameter.isVarArgs() && i == parameters.length - 1) {
|
||||||
clazz = parameter.getType().getComponentType();
|
clazz = parameter.getType().getComponentType();
|
||||||
}
|
}
|
||||||
if (clazz.isEnum()) {
|
Mapper mapper = parameter.getAnnotation(Mapper.class);
|
||||||
|
if (clazz.isEnum() && mapper == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String name = clazz.getTypeName();
|
String name = clazz.getTypeName();
|
||||||
Mapper mapper = parameter.getAnnotation(Mapper.class);
|
|
||||||
if (mapper != null) {
|
if (mapper != null) {
|
||||||
name = mapper.value();
|
name = mapper.value();
|
||||||
}
|
}
|
||||||
if (!SWCommandUtils.MAPPER_FUNCTIONS.containsKey(name)) return;
|
if (!SWCommandUtils.MAPPER_FUNCTIONS.containsKey(name)) return;
|
||||||
}
|
}
|
||||||
commandSet.add(new SubCommand(this, method));
|
commandMethods.add(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMapper(Method method) {
|
private void addMapper(Method method) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren