Added deprecation warning on plugin events

This commit is contained in:
Shoghi Cervantes 2014-07-10 17:39:20 +02:00
parent 1fab6bd589
commit 20b0df4b57
2 changed files with 9 additions and 1 deletions

View File

@ -666,9 +666,15 @@ class PluginManager{
$ignoreCancelled = true;
}
}
$parameters = $method->getParameters();
if(count($parameters) === 1 and $parameters[0]->getClass() instanceof \ReflectionClass and is_subclass_of($parameters[0]->getClass()->getName(), "pocketmine\\event\\Event")){
$this->registerEvent($parameters[0]->getClass()->getName(), $listener, $priority, new MethodEventExecutor($method->getName()), $plugin, $ignoreCancelled);
$class = $parameters[0]->getClass()->getName();
$reflection = new \ReflectionClass($class);
if(preg_match("/^[\t ]*\\* @deprecated[\t ]{1,}$/m", (string) $reflection->getDocComment(), $matches) > 0 and $this->server->getProperty("settings.deprecated-verbose", true)){
$this->server->getLogger()->warning('"'.$plugin->getName().'" has registered a listener for '.$class.' on method "'.get_class($listener).'::'.$method.', but the event is Deprecated.');
}
$this->registerEvent($class, $listener, $priority, new MethodEventExecutor($method->getName()), $plugin, $ignoreCancelled);
}
}
}
@ -688,6 +694,7 @@ class PluginManager{
if(!is_subclass_of($event, "pocketmine\\event\\Event")){
throw new \Exception($event . " is not a valid Event");
}
if(!$plugin->isEnabled()){
throw new \Exception("Plugin attempted to register " . $event . " while not enabled");
}

View File

@ -6,6 +6,7 @@ settings:
shutdown-message: "Server closed"
plugin-profiling: false
query-plugins: true
deprecated-verbose: true
advanced-cache: false
upnp-forwarding: false
send-usage: true