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:
Dylan K. Taylor 2018-07-10 16:59:33 +01:00 committed by GitHub
parent b01b477a2a
commit 9610c55b19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;