diff --git a/application/core/Plugins/Plugin.php b/application/core/Plugins/Plugin.php index 7ee87352..8734f0f4 100644 --- a/application/core/Plugins/Plugin.php +++ b/application/core/Plugins/Plugin.php @@ -5,39 +5,50 @@ namespace ManiaControl\Plugins; use ManiaControl\ManiaControl; /** - * Plugin parent class + * Interface for ManiaControl Plugins * * @author steeffeen & kremsy */ -abstract class Plugin { +interface Plugin { /** - * Plugin Metadata + * Constants */ - public static $name = 'undefined'; - public static $version = 'undefined'; - public static $author = 'undefined'; - public static $description = 'undefined'; - - /** - * Protected properties - */ - protected $maniaControl = null; + const PLUGIN_INTERFACE = __CLASS__; /** * Create a new plugin * * @param \ManiaControl\ManiaControl $maniaControl */ - public abstract function __construct(ManiaControl $maniaControl); + public function __construct(ManiaControl $maniaControl); /** - * Get class name as string + * Get Plugin Name * * @return string */ - public static final function getClass() { - return __CLASS__; - } + public static function getName(); + + /** + * Get Plugin Version + * + * @return float + */ + public static function getVersion(); + + /** + * Get Plugin Author + * + * @return string + */ + public static function getAuthor(); + + /** + * Get Plugin Description + * + * @return string + */ + public static function getDescription(); } ?> diff --git a/application/core/Plugins/PluginManager.php b/application/core/Plugins/PluginManager.php index 2b1c17f8..be6aaace 100644 --- a/application/core/Plugins/PluginManager.php +++ b/application/core/Plugins/PluginManager.php @@ -150,7 +150,7 @@ class PluginManager { $classesAfter = get_declared_classes(); $newClasses = array_diff($classesAfter, $classesBefore); foreach ($newClasses as $className) { - if (!is_subclass_of($className, Plugin::getClass())) { + if (!in_array(Plugin::PLUGIN_INTERFACE, class_implements($className))) { continue; } array_push($this->pluginClasses, $className); diff --git a/application/plugins/Chatlog.php b/application/plugins/Chatlog.php index b88fa37e..dfc97e16 100644 --- a/application/plugins/Chatlog.php +++ b/application/plugins/Chatlog.php @@ -10,11 +10,11 @@ use ManiaControl\Plugins\Plugin; * * @author steeffeen */ -class ChatlogPlugin extends Plugin implements CallbackListener { +class ChatlogPlugin implements CallbackListener, Plugin { /** * Constants */ - const VERSION = '1.0'; + const VERSION = 1.0; const SETTING_FOLDERNAME = 'Log-Folder Name'; const SETTING_FILENAME = 'Log-File Name'; const SETTING_USEPID = 'Use Process-Id for File Name'; @@ -28,16 +28,12 @@ class ChatlogPlugin extends Plugin implements CallbackListener { /** * Constuct chatlog plugin + * + * @param ManiaControl $maniaControl */ public function __construct(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; - // Plugin details - self::$name = 'Chatlog Plugin'; - self::$version = self::VERSION; - self::$author = 'steeffeen'; - self::$description = 'Plugin logging the chat messages of the server.'; - // Init settings $this->maniaControl->settingManager->initSetting($this, self::SETTING_FOLDERNAME, 'logs'); $this->maniaControl->settingManager->initSetting($this, self::SETTING_FILENAME, 'ChatLog.log'); @@ -75,6 +71,38 @@ class ChatlogPlugin extends Plugin implements CallbackListener { 'handlePlayerChatCallback'); } + /** + * + * @see \ManiaControl\Plugins\Plugin::getName() + */ + public static function getName() { + return 'Chatlog Plugin'; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getVersion() + */ + public static function getVersion() { + return self::VERSION; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getAuthor() + */ + public static function getAuthor() { + return 'steeffeen'; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getDescription() + */ + public static function getDescription() { + return 'Plugin logging the chat messages of the server.'; + } + /** * Handle PlayerChat callback * diff --git a/application/plugins/Donations.php b/application/plugins/Donations.php index ca767fc1..c5fb67e4 100644 --- a/application/plugins/Donations.php +++ b/application/plugins/Donations.php @@ -4,19 +4,19 @@ use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Commands\CommandListener; -use ManiaControl\Plugins\Plugin; use ManiaControl\Players\Player; +use ManiaControl\Plugins\Plugin; /** * Donation plugin * * @author steeffeen */ -class DonationPlugin extends Plugin implements CallbackListener, CommandListener { +class DonationPlugin implements CallbackListener, CommandListener, Plugin { /** * Constants */ - const VERSION = '1.0'; + const VERSION = 1.0; const SETTING_ANNOUNCE_SERVERDONATION = 'Enable Server-Donation Announcements'; /** @@ -32,12 +32,6 @@ class DonationPlugin extends Plugin implements CallbackListener, CommandListener public function __construct(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; - // Plugin details - self::$author = 'steeffeen'; - self::$name = 'Donation Plugin'; - self::$version = self::VERSION; - self::$description = 'DonationPlugin commands like /donate, /pay and /getplanets and a donation widget.'; - // Register for commands $this->maniaControl->commandManager->registerCommandListener('donate', $this, 'command_Donate'); $this->maniaControl->commandManager->registerCommandListener('/pay', $this, 'command_Pay'); @@ -47,6 +41,38 @@ class DonationPlugin extends Plugin implements CallbackListener, CommandListener $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_BILLUPDATED, $this, 'handleBillUpdated'); } + /** + * + * @see \ManiaControl\Plugins\Plugin::getName() + */ + public static function getName() { + return 'Donation Plugin'; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getVersion() + */ + public static function getVersion() { + return self::VERSION; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getAuthor() + */ + public static function getAuthor() { + return 'steeffeen'; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getDescription() + */ + public static function getDescription() { + return 'DonationPlugin commands like /donate, /pay and /getplanets and a donation widget.'; + } + /** * Handle /donate command * diff --git a/application/plugins/Endurance.php b/application/plugins/Endurance.php index 709fd841..308e0732 100644 --- a/application/plugins/Endurance.php +++ b/application/plugins/Endurance.php @@ -9,11 +9,11 @@ use ManiaControl\Plugins\Plugin; * * @author steeffeen */ -class EndurancePlugin extends Plugin implements CallbackListener { +class EndurancePlugin implements CallbackListener, Plugin { /** * Constants */ - const VERSION = '1.0'; + const VERSION = 1.0; const CB_CHECKPOINT = 'Endurance.Checkpoint'; /** @@ -30,18 +30,44 @@ class EndurancePlugin extends Plugin implements CallbackListener { public function __construct(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; - // Plugin information - self::$name = 'Endurance Plugin'; - self::$version = self::VERSION; - self::$author = 'steeffeen'; - self::$description = "Plugin enabling Support for the TM Game Mode 'Endurance' by TGYoshi."; - // 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'); } + /** + * + * @see \ManiaControl\Plugins\Plugin::getName() + */ + public static function getName() { + return 'Endurance Plugin'; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getVersion() + */ + public static function getVersion() { + return self::VERSION; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getAuthor() + */ + public static function getAuthor() { + return 'steeffeen'; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getDescription() + */ + public static function getDescription() { + return "Plugin enabling Support for the TM Game Mode 'Endurance' by TGYoshi."; + } + /** * Handle ManiaControl OnInit callback * diff --git a/application/plugins/Karma.php b/application/plugins/Karma.php index 1242de7e..26c313c4 100644 --- a/application/plugins/Karma.php +++ b/application/plugins/Karma.php @@ -19,11 +19,11 @@ use FML\Controls\Gauge; * * @author steeffeen */ -class KarmaPlugin extends Plugin implements CallbackListener { +class KarmaPlugin implements CallbackListener, Plugin { /** * Constants */ - const VERSION = '1.0'; + const VERSION = 1.0; const MLID_KARMA = 'KarmaPlugin.MLID'; const TABLE_KARMA = 'mc_karma'; const SETTING_AVAILABLE_VOTES = 'Available Votes (X-Y: Comma separated)'; @@ -33,6 +33,14 @@ class KarmaPlugin extends Plugin implements CallbackListener { 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 */ @@ -47,12 +55,6 @@ class KarmaPlugin extends Plugin implements CallbackListener { public function __construct(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; - // Plugin details - self::$name = 'Karma Plugin'; - self::$author = 'steeffeen'; - self::$version = self::VERSION; - self::$description = 'Plugin offering Karma Voting for Maps.'; - // Init database $this->initTables(); @@ -73,6 +75,38 @@ class KarmaPlugin extends Plugin implements CallbackListener { $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handlePlayerChat'); } + /** + * + * @see \ManiaControl\Plugins\Plugin::getName() + */ + public static function getName() { + return 'Karma Plugin'; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getVersion() + */ + public static function getVersion() { + return self::VERSION; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getAuthor() + */ + public static function getAuthor() { + return 'steeffeen'; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getDescription() + */ + public static function getDescription() { + return 'Plugin offering Karma Voting for Maps.'; + } + /** * Handle ManiaControl 1 Second callback * diff --git a/application/plugins/LocalRecords.php b/application/plugins/LocalRecords.php index a7267e29..b0df8964 100644 --- a/application/plugins/LocalRecords.php +++ b/application/plugins/LocalRecords.php @@ -20,11 +20,11 @@ use FML\Controls\Labels\Label_Text; * * @author steeffeen */ -class LocalRecordsPlugin extends Plugin implements CallbackListener { +class LocalRecordsPlugin implements CallbackListener, Plugin { /** * Constants */ - const VERSION = '1.0'; + const VERSION = 1.0; const MLID_RECORDS = 'ml_local_records'; const TABLE_RECORDS = 'mc_localrecords'; const SETTING_WIDGET_TITLE = 'Widget Title'; @@ -84,6 +84,38 @@ class LocalRecordsPlugin extends Plugin implements CallbackListener { } } + /** + * + * @see \ManiaControl\Plugins\Plugin::getName() + */ + public static function getName() { + return 'Local Records Plugin'; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getVersion() + */ + public static function getVersion() { + return self::VERSION; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getAuthor() + */ + public static function getAuthor() { + return 'steeffeen'; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getDescription() + */ + public static function getDescription() { + return 'Plugin offering tracking of local records and manialinks to display them.'; + } + /** * Handle ManiaControl init * diff --git a/application/plugins/Obstacle.php b/application/plugins/Obstacle.php index 47f6ea77..73017b74 100644 --- a/application/plugins/Obstacle.php +++ b/application/plugins/Obstacle.php @@ -12,11 +12,11 @@ use ManiaControl\Plugins\Plugin; * * @author steeffeen */ -class ObstaclePlugin extends Plugin implements CallbackListener, CommandListener { +class ObstaclePlugin implements CallbackListener, CommandListener, Plugin { /** * Constants */ - const VERSION = '1.0'; + const VERSION = 1.0; const CB_JUMPTO = 'Obstacle.JumpTo'; const SCB_ONFINISH = 'OnFinish'; const SCB_ONCHECKPOINT = 'OnCheckpoint'; @@ -28,12 +28,6 @@ class ObstaclePlugin extends Plugin implements CallbackListener, CommandListener public function __construct(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; - // Plugin details - self::$name = 'Obstacle Plugin'; - self::$version = self::VERSION; - self::$author = 'steeffeen'; - self::$description = 'Plugin offering various Commands for the ShootMania Obstacle Game Mode.'; - // Init settings $this->maniaControl->settingManager->initSetting($this, self::SETTING_JUMPTOAUTHLEVEL, AuthenticationManager::AUTH_LEVEL_OPERATOR); @@ -46,6 +40,38 @@ class ObstaclePlugin extends Plugin implements CallbackListener, CommandListener $this->maniaControl->callbackManager->registerScriptCallbackListener(self::SCB_ONCHECKPOINT, $this, 'callback_OnCheckpoint'); } + /** + * + * @see \ManiaControl\Plugins\Plugin::getName() + */ + public static function getName() { + return 'Obstacle Plugin'; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getVersion() + */ + public static function getVersion() { + return self::VERSION; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getAuthor() + */ + public static function getAuthor() { + return 'steeffeen'; + } + + /** + * + * @see \ManiaControl\Plugins\Plugin::getDescription() + */ + public static function getDescription() { + return 'Plugin offering various Commands for the ShootMania Obstacle Game Mode.'; + } + /** * Handle JumpTo command * @@ -56,7 +82,7 @@ class ObstaclePlugin extends Plugin implements CallbackListener, CommandListener $authLevel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_JUMPTOAUTHLEVEL); if (!$this->maniaControl->authenticationManager->checkRight($player, $authLevel)) { $this->maniaControl->authenticationManager->sendNotAllowed($player); - return false; + return; } // Send jump callback $params = explode(' ', $chatCallback[1][2], 2); @@ -64,7 +90,6 @@ class ObstaclePlugin extends Plugin implements CallbackListener, CommandListener if (!$this->maniaControl->client->query('TriggerModeScriptEvent', self::CB_JUMPTO, $param)) { trigger_error("Couldn't send jump callback for '{$player->login}'. " . $this->maniaControl->getClientErrorText()); } - return true; } /** @@ -91,6 +116,8 @@ class ObstaclePlugin extends Plugin implements CallbackListener, CommandListener * @param array $callback */ public function callback_OnCheckpoint(array $callback) { + // TODO: check back with trackmania callback format + return; $data = json_decode($callback[1]); $player = $this->maniaControl->playerManager->getPlayer($data->Player->Login); if (!$player) {