improved PluginManager

This commit is contained in:
kremsy 2017-05-22 22:01:23 +02:00
parent 988feea67d
commit d03f155415

View File

@ -170,6 +170,23 @@ class PluginManager {
$plugin = $this->activePlugins[$pluginClass]; $plugin = $this->activePlugins[$pluginClass];
unset($this->activePlugins[$pluginClass]); unset($this->activePlugins[$pluginClass]);
if ($plugin) {
$this->unloadPlugin($plugin);
}
$this->savePluginStatus($pluginClass, false);
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_PLUGIN_UNLOADED, $pluginClass, $plugin);
return true;
}
/**
* Unload the Plugin and all its Features
*
* @param \ManiaControl\Plugins\Plugin $plugin
*/
private function unloadPlugin(Plugin $plugin) {
$plugin->unload(); $plugin->unload();
if ($plugin instanceof EchoListener) { if ($plugin instanceof EchoListener) {
@ -188,18 +205,12 @@ class PluginManager {
if ($plugin instanceof TimerListener) { if ($plugin instanceof TimerListener) {
$this->maniaControl->getTimerManager()->unregisterTimerListenings($plugin); $this->maniaControl->getTimerManager()->unregisterTimerListenings($plugin);
} }
if($plugin instanceof SidebarMenuEntryListener){ if ($plugin instanceof SidebarMenuEntryListener) {
$this->maniaControl->getManialinkManager()->getSidebarMenuManager()->deleteMenuEntries($plugin); $this->maniaControl->getManialinkManager()->getSidebarMenuManager()->deleteMenuEntries($plugin);
} }
if($plugin instanceof CommunicationListener){ if ($plugin instanceof CommunicationListener) {
$this->maniaControl->getCommunicationManager()->unregisterCommunicationListener($plugin); $this->maniaControl->getCommunicationManager()->unregisterCommunicationListener($plugin);
} }
$this->savePluginStatus($pluginClass, false);
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_PLUGIN_UNLOADED, $pluginClass, $plugin);
return true;
} }
/** /**
@ -431,6 +442,9 @@ class PluginManager {
try { try {
$plugin->load($this->maniaControl); $plugin->load($this->maniaControl);
} catch (\Exception $e) { } catch (\Exception $e) {
//Unload the Plugin and all its features
$this->unloadPlugin($plugin);
$message = "Error during Plugin Activation of '{$pluginClass}': '{$e->getMessage()}'"; $message = "Error during Plugin Activation of '{$pluginClass}': '{$e->getMessage()}'";
$this->maniaControl->getChat()->sendError($message, $adminLogin); $this->maniaControl->getChat()->sendError($message, $adminLogin);
Logger::logError($message); Logger::logError($message);