mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Added constants for the handler tag types
This commit is contained in:
parent
742f86e022
commit
6cb285d4a9
34
src/event/ListenerMethodTags.php
Normal file
34
src/event/ListenerMethodTags.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\event;
|
||||
|
||||
/**
|
||||
* Provides constants for all the PhpDoc tags supported for Listener methods.
|
||||
* @see Listener
|
||||
*/
|
||||
final class ListenerMethodTags{
|
||||
public const HANDLE_CANCELLED = "handleCancelled";
|
||||
public const NOT_HANDLER = "notHandler";
|
||||
public const PRIORITY = "priority";
|
||||
}
|
@ -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] . "\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user