plugin class exception handling
This commit is contained in:
parent
d173a48159
commit
fb30706cd4
@ -5,8 +5,8 @@ namespace ManiaControl\Plugins;
|
|||||||
require_once __DIR__ . '/Plugin.php';
|
require_once __DIR__ . '/Plugin.php';
|
||||||
require_once __DIR__ . '/PluginMenu.php';
|
require_once __DIR__ . '/PluginMenu.php';
|
||||||
|
|
||||||
use ManiaControl\ManiaControl;
|
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -123,9 +123,10 @@ class PluginManager {
|
|||||||
* Activate and start the plugin with the given name
|
* Activate and start the plugin with the given name
|
||||||
*
|
*
|
||||||
* @param string $pluginClass
|
* @param string $pluginClass
|
||||||
|
* @param string $adminLogin
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function activatePlugin($pluginClass) {
|
public function activatePlugin($pluginClass, $adminLogin = false) {
|
||||||
if(!is_string($pluginClass)) {
|
if(!is_string($pluginClass)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -136,7 +137,14 @@ class PluginManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$plugin = new $pluginClass();
|
$plugin = new $pluginClass();
|
||||||
|
try {
|
||||||
$plugin->load($this->maniaControl);
|
$plugin->load($this->maniaControl);
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
$this->maniaControl->chat->sendError('Error on Plugin activation ' . $e->getMessage(), $adminLogin);
|
||||||
|
$this->log('Error while plugin activation: ' . $e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$this->activePlugins[$pluginClass] = $plugin;
|
$this->activePlugins[$pluginClass] = $plugin;
|
||||||
$this->savePluginStatus($pluginClass, true);
|
$this->savePluginStatus($pluginClass, true);
|
||||||
return true;
|
return true;
|
||||||
|
@ -199,7 +199,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu {
|
|||||||
}
|
}
|
||||||
if($enable) {
|
if($enable) {
|
||||||
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_ENABLEPLUGIN));
|
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_ENABLEPLUGIN));
|
||||||
$activated = $this->maniaControl->pluginManager->activatePlugin($pluginClass);
|
$activated = $this->maniaControl->pluginManager->activatePlugin($pluginClass, $player->login);
|
||||||
if($activated) {
|
if($activated) {
|
||||||
$this->maniaControl->chat->sendSuccess($pluginClass::getName() . ' activated!', $player->login);
|
$this->maniaControl->chat->sendSuccess($pluginClass::getName() . ' activated!', $player->login);
|
||||||
$this->maniaControl->configurator->showMenu($player);
|
$this->maniaControl->configurator->showMenu($player);
|
||||||
|
Loading…
Reference in New Issue
Block a user