From a7e5f502623a470e20c72f2930455d1c796dabc2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 16 Apr 2021 17:03:07 +0200 Subject: [PATCH] Fix CCE in SubCommand.invoke --- SpigotCore_Main/src/de/steamwar/command/SubCommand.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java index b7a414b..86cfdc7 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java @@ -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 commandSenderPredicate; private Function 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);