Fix CCE in SubCommand.invoke #100
@ -26,6 +26,7 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
class SubCommand {
|
||||
|
||||
@ -33,6 +34,7 @@ class SubCommand {
|
||||
private Method method;
|
||||
String[] subCommand;
|
||||
TypeMapper<?>[] arguments;
|
||||
private Predicate<CommandSender> commandSenderPredicate;
|
||||
private Function<CommandSender, ?> commandSenderFunction;
|
||||
Class<?> varArgType = null;
|
||||
|
||||
@ -45,6 +47,7 @@ class SubCommand {
|
||||
this.method = method;
|
||||
|
||||
Parameter[] parameters = method.getParameters();
|
||||
commandSenderPredicate = sender -> parameters[0].getType().isAssignableFrom(sender.getClass());
|
||||
commandSenderFunction = sender -> parameters[0].getType().cast(sender);
|
||||
this.subCommand = subCommand;
|
||||
|
||||
@ -88,6 +91,9 @@ class SubCommand {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if (!commandSenderPredicate.test(commandSender)) {
|
||||
return false;
|
||||
}
|
||||
Object[] objects = SWCommandUtils.generateArgumentArray(commandSender, arguments, args, varArgType, subCommand);
|
||||
objects[0] = commandSenderFunction.apply(commandSender);
|
||||
method.setAccessible(true);
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren