Plugin load and unload methods

This commit is contained in:
Steffen Schröder 2013-12-14 23:29:17 +01:00
parent fd3a3056f1
commit f4cbace654
7 changed files with 113 additions and 38 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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
*/

View File

@ -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()

View File

@ -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;

View File

@ -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;

View File

@ -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) {