diff --git a/application/core/Plugins/Plugin.php b/application/core/Plugins/Plugin.php index ae276a2b..ed23245a 100644 --- a/application/core/Plugins/Plugin.php +++ b/application/core/Plugins/Plugin.php @@ -16,11 +16,17 @@ interface Plugin { const PLUGIN_INTERFACE = __CLASS__; /** - * Create a new plugin + * Load the plugin * * @param \ManiaControl\ManiaControl $maniaControl + * @return bool */ - public function __construct(ManiaControl $maniaControl); + public function load(ManiaControl $maniaControl); + + /** + * Unload the plugin and its resources + */ + public function unload(); /** * Get plugin id diff --git a/application/plugins/Chatlog.php b/application/plugins/Chatlog.php index e23c5c7f..b918909e 100644 --- a/application/plugins/Chatlog.php +++ b/application/plugins/Chatlog.php @@ -24,15 +24,15 @@ class ChatlogPlugin implements CallbackListener, Plugin { /** * Private properties */ + private $maniaControl = null; private $fileName = null; private $logServerMessages = true; /** - * Construct chatlog plugin * - * @param ManiaControl $maniaControl + * @see \ManiaControl\Plugins\Plugin::load() */ - public function __construct(ManiaControl $maniaControl) { + public function load(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; // Init settings @@ -70,6 +70,17 @@ class ChatlogPlugin implements CallbackListener, Plugin { // Register for callbacks $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handlePlayerChatCallback'); + + return true; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::unload() + */ + public function unload() { + $this->maniaControl->callbackManager->unregisterCallbackListener($this); + unset($this->maniaControl); } /** @@ -129,7 +140,7 @@ class ChatlogPlugin implements CallbackListener, Plugin { /** * Log the given message * - * @param string $text + * @param string $text * @param string $login */ private function logText($text, $login = null) { diff --git a/application/plugins/Donations.php b/application/plugins/Donations.php index 630eb9dd..e8da019f 100644 --- a/application/plugins/Donations.php +++ b/application/plugins/Donations.php @@ -23,23 +23,35 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin { /** * Private properties */ + private $maniaControl = null; private $openBills = array(); /** - * Construct donation plugin * - * @param \ManiaControl\ManiaControl $maniaControl + * @see \ManiaControl\Plugins\Plugin::load() */ - public function __construct(ManiaControl $maniaControl) { + public function load(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; // Register for commands $this->maniaControl->commandManager->registerCommandListener('donate', $this, 'command_Donate'); - $this->maniaControl->commandManager->registerCommandListener('/pay', $this, 'command_Pay'); - $this->maniaControl->commandManager->registerCommandListener('/getplanets', $this, 'command_GetPlanets'); + $this->maniaControl->commandManager->registerCommandListener('pay', $this, 'command_Pay', true); + $this->maniaControl->commandManager->registerCommandListener('getplanets', $this, 'command_GetPlanets', true); // Register for callbacks $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_BILLUPDATED, $this, 'handleBillUpdated'); + + return true; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::unload() + */ + public function unload() { + $this->maniaControl->callbackManager->unregisterCallbackListener($this); + $this->maniaControl->commandManager->unregisterCommandListener($this); + unset($this->maniaControl); } /** @@ -168,7 +180,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin { /** * Handle //getplanets command * - * @param array $chatCallback + * @param array $chatCallback * @param Player $player * @return bool */ diff --git a/application/plugins/Endurance.php b/application/plugins/Endurance.php index be4f93fe..10c9dff6 100644 --- a/application/plugins/Endurance.php +++ b/application/plugins/Endurance.php @@ -20,23 +20,34 @@ class EndurancePlugin implements CallbackListener, Plugin { /** * Private properties */ + private $maniaControl = null; private $currentMap = null; private $playerLapTimes = array(); /** - * Create a new endurance plugin instance * - * @param ManiaControl $maniaControl + * @see \ManiaControl\Plugins\Plugin::load() */ - public function __construct(ManiaControl $maniaControl) { + public function load(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; // Register for callbacks $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'callback_OnInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'callback_BeginMap'); $this->maniaControl->callbackManager->registerScriptCallbackListener(self::CB_CHECKPOINT, $this, 'callback_Checkpoint'); + + return true; } + /** + * + * @see \ManiaControl\Plugins\Plugin::unload() + */ + public function unload() { + $this->maniaControl->callbackManager->unregisterCallbackListener($this); + $this->maniaControl->callbackManager->unregisterScriptCallbackListener($this); + unset($this->maniaControl); + } /** * @@ -45,6 +56,7 @@ class EndurancePlugin implements CallbackListener, Plugin { public static function getId() { return self::ID; } + /** * * @see \ManiaControl\Plugins\Plugin::getName() diff --git a/application/plugins/Karma.php b/application/plugins/Karma.php index dd1638ec..cfb11447 100644 --- a/application/plugins/Karma.php +++ b/application/plugins/Karma.php @@ -32,26 +32,18 @@ class KarmaPlugin implements CallbackListener, Plugin { const SETTING_WIDGET_WIDTH = 'Widget-Size: Width'; const SETTING_WIDGET_HEIGHT = 'Widget-Size: Height'; - /** - * Plugin metadata - */ - public static $name = 'Karma Plugin'; - public static $author = 'steeffeen'; - public static $version = '1.0'; - public static $description = 'Plugin offering Karma Voting for Maps.'; - /** * Private properties */ + private $maniaControl = null; private $updateManialink = false; private $manialink = null; /** - * Create new karma plugin instance - * - * @param ManiaControl $maniaControl + * + * @see \ManiaControl\Plugins\Plugin::load() */ - public function __construct(ManiaControl $maniaControl) { + public function load(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; // Init database @@ -72,8 +64,18 @@ class KarmaPlugin implements CallbackListener, Plugin { $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handlePlayerChat'); + + return true; } + /** + * + * @see \ManiaControl\Plugins\Plugin::unload() + */ + public function unload() { + $this->maniaControl->callbackManager->unregisterCallbackListener($this); + unset($this->maniaControl); + } /** * @@ -82,6 +84,7 @@ class KarmaPlugin implements CallbackListener, Plugin { public static function getId() { return self::ID; } + /** * * @see \ManiaControl\Plugins\Plugin::getName() @@ -359,8 +362,8 @@ class KarmaPlugin implements CallbackListener, Plugin { /** * Get the current karma of the map * - * @param Map $map - * @return float | bool + * @param Map $map + * @return float | bool */ private function getMapKarma(Map $map) { $mysqli = $this->maniaControl->database->mysqli; @@ -388,8 +391,8 @@ class KarmaPlugin implements CallbackListener, Plugin { /** * Get the current Votes for the Map * - * @param Map $map - * @return array + * @param Map $map + * @return array */ private function getMapVotes(Map $map) { $mysqli = $this->maniaControl->database->mysqli; diff --git a/application/plugins/LocalRecords.php b/application/plugins/LocalRecords.php index b5e069f0..8b8f5137 100644 --- a/application/plugins/LocalRecords.php +++ b/application/plugins/LocalRecords.php @@ -36,12 +36,14 @@ class LocalRecordsPlugin implements CallbackListener, Plugin { /** * Private properties */ + private $maniaControl = null; private $updateManialink = false; /** - * Create new local records plugin + * + * @see \ManiaControl\Plugins\Plugin::load() */ - public function __construct(ManiaControl $maniaControl) { + public function load(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; $this->initTables(); @@ -61,6 +63,17 @@ class LocalRecordsPlugin implements CallbackListener, Plugin { 'handleClientUpdated'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERFINISH, $this, 'handlePlayerFinish'); + + return true; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::unload() + */ + public function unload() { + $this->maniaControl->callbackManager->unregisterCallbackListener($this); + unset($this->maniaControl); } /** @@ -255,7 +268,7 @@ class LocalRecordsPlugin implements CallbackListener, Plugin { /** * Handle ClientUpdated callback * - * @param array $callback + * @param array $callback */ public function handleClientUpdated(array $callback) { $this->updateManialink = true; diff --git a/application/plugins/Obstacle.php b/application/plugins/Obstacle.php index b94823e2..a7df6c8f 100644 --- a/application/plugins/Obstacle.php +++ b/application/plugins/Obstacle.php @@ -22,11 +22,17 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin { const SCB_ONFINISH = 'OnFinish'; const SCB_ONCHECKPOINT = 'OnCheckpoint'; const SETTING_JUMPTOAUTHLEVEL = 'Authentication level for JumpTo commands'; + + /** + * Private Properties + */ + private $maniaControl = null; /** - * Create new obstacle plugin + * + * @see \ManiaControl\Plugins\Plugin::load() */ - public function __construct(ManiaControl $maniaControl) { + public function load(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; // Init settings @@ -39,8 +45,19 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin { // Register for callbacks $this->maniaControl->callbackManager->registerScriptCallbackListener(self::SCB_ONFINISH, $this, 'callback_OnFinish'); $this->maniaControl->callbackManager->registerScriptCallbackListener(self::SCB_ONCHECKPOINT, $this, 'callback_OnCheckpoint'); + + return true; } + /** + * + * @see \ManiaControl\Plugins\Plugin::unload() + */ + public function unload() { + $this->maniaControl->commandManager->unregisterCommandListener($this); + $this->maniaControl->callbackManager->unregisterScriptCallbackListener($this); + unset($this->maniaControl); + } /** * @@ -49,6 +66,7 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin { public static function getId() { return self::ID; } + /** * * @see \ManiaControl\Plugins\Plugin::getName() @@ -84,8 +102,8 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin { /** * Handle JumpTo command * - * @param array $chatCallback - * @param Player $player + * @param array $chatCallback + * @param Player $player * @return bool */ public function command_JumpTo(array $chatCallback, Player $player) {