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 12 neuen und 27 gelöschten Zeilen
Nur Änderungen aus Commit ccb63e1613 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -76,7 +76,6 @@ public abstract class SWCommand {
}
});
Set<Method> commandMethods = new HashSet<>();
for (Method method : getClass().getDeclaredMethods()) {
add(Mapper.class, method, i -> i != 0, false, TypeMapper.class, (anno, parameters) -> {
try {
@ -87,6 +86,11 @@ public abstract class SWCommand {
throw new SecurityException(e.getMessage(), e);
}
});
add(RegisterHelp.class, method, i -> i != 1, true, null, (anno, parameters) -> {
commandHelpSet.add(new SubCommand(this, method, anno.value()));
});
}
for (Method method : getClass().getDeclaredMethods()) {
add(Register.class, method, i -> i == 0, true, null, (anno, parameters) -> {
for (int i = 1; i < parameters.length; i++) {
Parameter parameter = parameters[i];
@ -104,13 +108,9 @@ public abstract class SWCommand {
}
if (!SWCommandUtils.MAPPER_FUNCTIONS.containsKey(name)) return;
}
commandMethods.add(method);
});
add(RegisterHelp.class, method, i -> i != 1, true, null, (anno, parameters) -> {
commandHelpSet.add(new SubCommand(this, method));
commandSet.add(new SubCommand(this, method, anno.value()));
});
}
commandMethods.forEach(method -> commandSet.add(new SubCommand(this, method)));
}
private <T extends Annotation> void add(Class<T> annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class<?> returnType, BiConsumer<T, Parameter[]> consumer) {

Datei anzeigen

@ -39,21 +39,13 @@ class SubCommand {
private boolean varArgs = false;
private Function<CommandSender, ?> commandSenderFunction;
public SubCommand(SWCommand swCommand, Method method) {
public SubCommand(SWCommand swCommand, Method method, String[] subCommand) {
this.swCommand = swCommand;
this.method = method;
Parameter[] parameters = method.getParameters();
commandSenderFunction = sender -> parameters[0].getType().cast(sender);
SWCommand.Register register = SWCommandUtils.getAnnotation(method, SWCommand.Register.class);
SWCommand.RegisterHelp registerHelp = SWCommandUtils.getAnnotation(method, SWCommand.RegisterHelp.class);
if (register != null) {
subCommand = register.value();
} else if (registerHelp != null) {
subCommand = registerHelp.value();
} else {
throw new SecurityException();
}
this.subCommand = subCommand;
arguments = new TypeMapper[parameters.length - 1];
for (int i = 1; i < parameters.length; i++) {
@ -71,17 +63,7 @@ class SubCommand {
for (Enum<?> enumConstant : enumClass.getEnumConstants()) {
tabCompletes.add(enumConstant.name().toLowerCase());
}
arguments[i] = new TypeMapper<Object>() {
@Override
public Object map(String s) {
return SWCommandUtils.ENUM_MAPPER.apply(enumClass, s);
}
@Override
public List<String> tabCompletes(String s) {
return tabCompletes;
}
};
arguments[i] = SWCommandUtils.createMapper(s -> SWCommandUtils.ENUM_MAPPER.apply(enumClass, s), s -> tabCompletes);
continue;
}
@ -112,6 +94,9 @@ class SubCommand {
}
List<String> tabComplete(CommandSender commandSender, String[] args) {
if (!varArgs && args.length < arguments.length - 1) {
return Collections.emptyList();
}
List<String> argsList = Arrays.asList(args);
Veraltet
Review

Ich denke mal, das throw new SecurityException aus der Zeile drüber wäre auch angebracht. Auf jeden Fall für "RuntimeException".

Ich denke mal, das throw new SecurityException aus der Zeile drüber wäre auch angebracht. Auf jeden Fall für "RuntimeException".
for (String value : subCommand) {
String s = argsList.remove(0);