SteamWar/SpigotCore
Archiviert
13
0

CommandFramework #107

Geschlossen
YoyoNow möchte 27 Commits von CommandFramework nach master mergen
Nur Änderungen aus Commit 7ea204b289 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -19,7 +19,6 @@
package de.steamwar.command;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
@ -32,7 +31,6 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.IntPredicate;
import java.util.logging.Level;
import java.util.stream.Collectors;
public abstract class SWCommand {
@ -86,19 +84,14 @@ public abstract class SWCommand {
});
add(Register.class, method, i -> i > 0, true, null, (anno, parameters) -> {
if (!anno.help()) return;
List<String> errors = new ArrayList<>();
if (parameters.length != 2) {
errors.add("The method '" + method.toString() + "' is lacking parameters or has too many");
throw new SecurityException("The method '" + method.toString() + "' is lacking parameters or has too many");
}
if (!parameters[parameters.length - 1].isVarArgs()) {
errors.add("The method '" + method.toString() + "' is lacking the varArgs parameters as last Argument");
throw new SecurityException("The method '" + method.toString() + "' is lacking the varArgs parameters as last Argument");
}
if (parameters[parameters.length - 1].getType().getComponentType() != String.class) {
errors.add("The method '" + method.toString() + "' is lacking the varArgs parameters of type '" + String.class.getTypeName() + "' as last Argument");
}
if (!errors.isEmpty()) {
errors.forEach(s -> Bukkit.getLogger().log(Level.WARNING, s));
return;
throw new SecurityException("The method '" + method.toString() + "' is lacking the varArgs parameters of type '" + String.class.getTypeName() + "' as last Argument");
}
commandHelpList.add(new SubCommand(this, method, anno.description(), anno.value(), new HashMap<>()));
});
@ -118,8 +111,7 @@ public abstract class SWCommand {
}
String name = mapper != null ? mapper.value() : clazz.getTypeName();
if (!SWCommandUtils.MAPPER_FUNCTIONS.containsKey(name) && !localTypeMapper.containsKey(name)) {
Bukkit.getLogger().log(Level.WARNING, "The parameter '" + parameter.toString() + "' is using an unsupported Mapper of type '" + name + "'");
return;
throw new SecurityException("The parameter '" + parameter.toString() + "' is using an unsupported Mapper of type '" + name + "'");
}
}
commandList.add(new SubCommand(this, method, anno.description(), anno.value(), localTypeMapper));
@ -174,19 +166,14 @@ public abstract class SWCommand {
if (anno == null || anno.length == 0) return;
Parameter[] parameters = method.getParameters();
List<String> errors = new ArrayList<>();
if (!parameterTester.test(parameters.length)) {
errors.add("The method '" + method.toString() + "' is lacking parameters or has too many");
throw new SecurityException("The method '" + method.toString() + "' is lacking parameters or has too many");
}
if (firstParameter && !CommandSender.class.isAssignableFrom(parameters[0].getType())) {
errors.add("The method '" + method.toString() + "' is lacking the first parameter of type '" + CommandSender.class.getTypeName() + "'");
throw new SecurityException("The method '" + method.toString() + "' is lacking the first parameter of type '" + CommandSender.class.getTypeName() + "'");
}
if (returnType != null && method.getReturnType() != returnType) {
errors.add("The method '" + method.toString() + "' is lacking the desired return type '" + returnType.getTypeName() + "'");
}
if (!errors.isEmpty()) {
errors.forEach(s -> Bukkit.getLogger().log(Level.WARNING, s));
return;
throw new SecurityException("The method '" + method.toString() + "' is lacking the desired return type '" + returnType.getTypeName() + "'");
}
Arrays.stream(anno).forEach(t -> consumer.accept(t, parameters));
}