SteamWar/SpigotCore
Archiviert
13
0

CommandFramework3 #94

Manuell gemergt
Zeanon hat 71 Commits von CommandFramework3 nach master 2021-03-30 21:15:40 +02:00 zusammengeführt
2 geänderte Dateien mit 22 neuen und 24 gelöschten Zeilen
Nur Änderungen aus Commit 529b3daf6c werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -81,32 +81,14 @@ public abstract class SWCommand {
});
for (Method method : getClass().getDeclaredMethods()) {
add(Mapper.class, method, i -> i != 0, false, TypeMapper.class, (anno, parameters) -> {
try {
method.setAccessible(true);
Object object = method.invoke(this);
SWCommandUtils.addMapper(anno.value(), (TypeMapper<?>) object);
} catch (Exception e) {
throw new SecurityException(e.getMessage(), e);
}
addMapper(Mapper.class, method, i -> i != 0, false, TypeMapper.class, (anno, typeMapper) -> {
SWCommandUtils.addMapper(anno.value(), typeMapper);
});
add(ClassMapper.class, method, i -> i != 0, false, TypeMapper.class, (anno, parameters) -> {
try {
method.setAccessible(true);
Object object = method.invoke(this);
SWCommandUtils.addMapper(anno.value().getTypeName(), (TypeMapper<?>) object);
} catch (Exception e) {
throw new SecurityException(e.getMessage(), e);
}
addMapper(ClassMapper.class, method, i -> i != 0, false, TypeMapper.class, (anno, typeMapper) -> {
SWCommandUtils.addMapper(anno.value().getTypeName(), typeMapper);
});
add(LocalMapper.class, method, i -> i != 0, false, TypeMapper.class, (anno, parameters) -> {
try {
method.setAccessible(true);
Object object = method.invoke(this);
localTypeMapper.put(anno.value(), (TypeMapper<?>) object);
} catch (Exception e) {
throw new SecurityException(e.getMessage(), e);
}
addMapper(LocalMapper.class, method, i -> i != 0, false, TypeMapper.class, (anno, typeMapper) -> {
localTypeMapper.put(anno.value(), typeMapper);
});
add(RegisterHelp.class, method, i -> i != 1, true, null, (anno, parameters) -> {
if (!parameters[parameters.length - 1].isVarArgs()) {
@ -160,6 +142,18 @@ public abstract class SWCommand {
consumer.accept(anno, parameters);
}
private <T extends Annotation> void addMapper(Class<T> annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class<?> returnType, BiConsumer<T, TypeMapper<?>> consumer) {
add(annotation, method, parameterTester, firstParameter, returnType, (anno, parameters) -> {
try {
method.setAccessible(true);
Object object = method.invoke(this);
consumer.accept(anno, (TypeMapper<?>) object);
} catch (Exception e) {
throw new SecurityException(e.getMessage(), e);
}
});
}
protected boolean isEnabled() {
return enabled;
}

Datei anzeigen

@ -116,6 +116,10 @@ public class SWCommandUtils {
return arguments;
}
public static <T> void addMapper(Class<T> clazz, TypeMapper<T> mapper) {
addMapper(clazz.getTypeName(), mapper);
}
public static void addMapper(String name, TypeMapper<?> mapper) {
if (MAPPER_FUNCTIONS.containsKey(name)) return;
MAPPER_FUNCTIONS.put(name, mapper);