mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
PluginManager: Skip methods not declared by instanceof Listener when registering handlers (#2293)
This is quite an interesting bug. If you have ```php class A{ public function onMove(PlayerMoveEvent $event){} //shouldn't be a handler because this class isn't a Listener } class B extends A implements Listener{} ``` then ```php registerEvents(new B, $plugin); ``` then `A::onMove()` will be registered as an event handler even though `A` is not an instanceof `Listener`. This was observed by noting that plugins which do something like `extends PluginBase implements Listener` causes `registerEvents()` to try and register `PluginBase` methods as event handlers, which could lead to astonishing behaviour. then A::onMove() will be registered as an event handler even though A is not an instanceof Listener. This was observed by noting that plugins which do something like "extends PluginBase implements Listener" causes registerEvents() to try and register PluginBase methods as event handlers, which could lead to astonishing behaviour.
This commit is contained in:
parent
b01b477a2a
commit
9610c55b19
@ -783,7 +783,7 @@ class PluginManager{
|
||||
|
||||
$reflection = new \ReflectionClass(get_class($listener));
|
||||
foreach($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method){
|
||||
if(!$method->isStatic()){
|
||||
if(!$method->isStatic() and $method->getDeclaringClass()->implementsInterface(Listener::class)){
|
||||
$tags = Utils::parseDocComment((string) $method->getDocComment());
|
||||
if(isset($tags["notHandler"])){
|
||||
continue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user