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