Added constants for the handler tag types

This commit is contained in:
Dylan K. Taylor
2021-05-06 18:40:14 +01:00
parent 742f86e022
commit 6cb285d4a9
2 changed files with 41 additions and 6 deletions

View File

@@ -27,6 +27,7 @@ use pocketmine\event\Event;
use pocketmine\event\EventPriority;
use pocketmine\event\HandlerListManager;
use pocketmine\event\Listener;
use pocketmine\event\ListenerMethodTags;
use pocketmine\event\plugin\PluginDisableEvent;
use pocketmine\event\plugin\PluginEnableEvent;
use pocketmine\event\RegisteredListener;
@@ -450,7 +451,7 @@ class PluginManager{
foreach($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method){
if(!$method->isStatic() and $method->getDeclaringClass()->implementsInterface(Listener::class)){
$tags = Utils::parseDocComment((string) $method->getDocComment());
if(isset($tags["notHandler"])){
if(isset($tags[ListenerMethodTags::NOT_HANDLER])){
continue;
}
@@ -476,14 +477,14 @@ class PluginManager{
if($handlerClosure === null) throw new AssumptionFailedError("This should never happen");
try{
$priority = isset($tags["priority"]) ? EventPriority::fromString($tags["priority"]) : EventPriority::NORMAL;
$priority = isset($tags[ListenerMethodTags::PRIORITY]) ? EventPriority::fromString($tags[ListenerMethodTags::PRIORITY]) : EventPriority::NORMAL;
}catch(\InvalidArgumentException $e){
throw new PluginException("Event handler " . Utils::getNiceClosureName($handlerClosure) . "() declares invalid/unknown priority \"" . $tags["priority"] . "\"");
throw new PluginException("Event handler " . Utils::getNiceClosureName($handlerClosure) . "() declares invalid/unknown priority \"" . $tags[ListenerMethodTags::PRIORITY] . "\"");
}
$handleCancelled = false;
if(isset($tags["handleCancelled"])){
switch(strtolower($tags["handleCancelled"])){
if(isset($tags[ListenerMethodTags::HANDLE_CANCELLED])){
switch(strtolower($tags[ListenerMethodTags::HANDLE_CANCELLED])){
case "true":
case "":
$handleCancelled = true;
@@ -491,7 +492,7 @@ class PluginManager{
case "false":
break;
default:
throw new PluginException("Event handler " . Utils::getNiceClosureName($handlerClosure) . "() declares invalid @handleCancelled value \"" . $tags["handleCancelled"] . "\"");
throw new PluginException("Event handler " . Utils::getNiceClosureName($handlerClosure) . "() declares invalid @" . ListenerMethodTags::HANDLE_CANCELLED . " value \"" . $tags[ListenerMethodTags::HANDLE_CANCELLED] . "\"");
}
}