SteamWar/SpigotCore
Archiviert
13
0

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:
YoyoNow 2021-04-16 17:19:41 +02:00
Commit f0c4786800

Datei anzeigen

@ -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);