diff --git a/src/pocketmine/plugin/PluginManager.php b/src/pocketmine/plugin/PluginManager.php index eb0b12c62..767bc7134 100644 --- a/src/pocketmine/plugin/PluginManager.php +++ b/src/pocketmine/plugin/PluginManager.php @@ -481,11 +481,14 @@ class PluginManager{ if(count($parameters) !== 1){ continue; } + + $handlerClosure = $method->getClosure($listener); + try{ $eventClass = $parameters[0]->getClass(); }catch(\ReflectionException $e){ //class doesn't exist if(isset($tags["softDepend"]) && !isset($this->plugins[$tags["softDepend"]])){ - $this->server->getLogger()->debug("Not registering @softDepend listener " . get_class($listener) . "::" . $method->getName() . "(" . $parameters[0]->getType()->getName() . ") because plugin \"" . $tags["softDepend"] . "\" not found"); + $this->server->getLogger()->debug("Not registering @softDepend listener " . Utils::getNiceClosureName($handlerClosure) . "(" . $parameters[0]->getType()->getName() . ") because plugin \"" . $tags["softDepend"] . "\" not found"); continue; } @@ -498,7 +501,7 @@ class PluginManager{ try{ $priority = isset($tags["priority"]) ? EventPriority::fromString($tags["priority"]) : EventPriority::NORMAL; }catch(\InvalidArgumentException $e){ - throw new PluginException("Event handler " . get_class($listener) . "->" . $method->getName() . "() declares invalid/unknown priority \"" . $tags["priority"] . "\""); + throw new PluginException("Event handler " . Utils::getNiceClosureName($handlerClosure) . "() declares invalid/unknown priority \"" . $tags["priority"] . "\""); } $ignoreCancelled = false; @@ -512,7 +515,7 @@ class PluginManager{ $ignoreCancelled = false; break; default: - throw new PluginException("Event handler " . get_class($listener) . "->" . $method->getName() . "() declares invalid @ignoreCancelled value \"" . $tags["ignoreCancelled"] . "\""); + throw new PluginException("Event handler " . Utils::getNiceClosureName($handlerClosure) . "() declares invalid @ignoreCancelled value \"" . $tags["ignoreCancelled"] . "\""); } } diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index f2eeeb26c..5989de29f 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -62,6 +62,21 @@ class Utils{ */ public static function getNiceClosureName(\Closure $closure) : string{ $func = new \ReflectionFunction($closure); + if($func->getName() !== "{closure}"){ + //closure wraps a named function, can be done with reflection or fromCallable() + //isClosure() is useless here because it just tells us if $func is reflecting a Closure object + + $scope = $func->getClosureScopeClass(); + if($scope !== null){ //class method + return + $scope->getName() . + ($func->getClosureThis() !== null ? "->" : "::") . + $func->getName(); //name doesn't include class in this case + } + + //non-class function + return $func->getName(); + } return "closure@" . self::cleanPath($func->getFileName()) . "#L" . $func->getStartLine(); }