mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-05 17:36:12 +00:00
Merge branch 'release/3.3'
This commit is contained in:
@ -41,7 +41,6 @@ use pocketmine\utils\Utils;
|
||||
* Manages all the plugins
|
||||
*/
|
||||
class PluginManager{
|
||||
private const MAX_EVENT_CALL_DEPTH = 50;
|
||||
|
||||
/** @var Server */
|
||||
private $server;
|
||||
@ -64,9 +63,6 @@ class PluginManager{
|
||||
*/
|
||||
protected $fileAssociations = [];
|
||||
|
||||
/** @var int */
|
||||
private $eventCallDepth = 0;
|
||||
|
||||
/** @var string|null */
|
||||
private $pluginDataDirectory;
|
||||
|
||||
@ -420,7 +416,7 @@ class PluginManager{
|
||||
|
||||
$this->enabledPlugins[$plugin->getDescription()->getName()] = $plugin;
|
||||
|
||||
$this->server->getPluginManager()->callEvent(new PluginEnableEvent($plugin));
|
||||
(new PluginEnableEvent($plugin))->call();
|
||||
}catch(\Throwable $e){
|
||||
$this->server->getLogger()->logException($e);
|
||||
$this->disablePlugin($plugin);
|
||||
@ -497,7 +493,7 @@ class PluginManager{
|
||||
public function disablePlugin(Plugin $plugin){
|
||||
if($plugin->isEnabled()){
|
||||
$this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.plugin.disable", [$plugin->getDescription()->getFullName()]));
|
||||
$this->callEvent(new PluginDisableEvent($plugin));
|
||||
(new PluginDisableEvent($plugin))->call();
|
||||
|
||||
unset($this->enabledPlugins[$plugin->getDescription()->getName()]);
|
||||
|
||||
@ -531,44 +527,13 @@ class PluginManager{
|
||||
/**
|
||||
* Calls an event
|
||||
*
|
||||
* @deprecated
|
||||
* @see Event::call()
|
||||
*
|
||||
* @param Event $event
|
||||
*/
|
||||
public function callEvent(Event $event){
|
||||
if($this->eventCallDepth >= self::MAX_EVENT_CALL_DEPTH){
|
||||
//this exception will be caught by the parent event call if all else fails
|
||||
throw new \RuntimeException("Recursive event call detected (reached max depth of " . self::MAX_EVENT_CALL_DEPTH . " calls)");
|
||||
}
|
||||
|
||||
$handlerList = HandlerList::getHandlerListFor(get_class($event));
|
||||
assert($handlerList !== null, "Called event should have a valid HandlerList");
|
||||
|
||||
++$this->eventCallDepth;
|
||||
foreach(EventPriority::ALL as $priority){
|
||||
$currentList = $handlerList;
|
||||
while($currentList !== null){
|
||||
foreach($currentList->getListenersByPriority($priority) as $registration){
|
||||
if(!$registration->getPlugin()->isEnabled()){
|
||||
continue;
|
||||
}
|
||||
|
||||
try{
|
||||
$registration->callEvent($event);
|
||||
}catch(\Throwable $e){
|
||||
$this->server->getLogger()->critical(
|
||||
$this->server->getLanguage()->translateString("pocketmine.plugin.eventError", [
|
||||
$event->getEventName(),
|
||||
$registration->getPlugin()->getDescription()->getFullName(),
|
||||
$e->getMessage(),
|
||||
get_class($registration->getListener())
|
||||
]));
|
||||
$this->server->getLogger()->logException($e);
|
||||
}
|
||||
}
|
||||
|
||||
$currentList = $currentList->getParent();
|
||||
}
|
||||
}
|
||||
--$this->eventCallDepth;
|
||||
$event->call();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user