Changed Plugin Class to Interface! (Final)

-> static methods for Name, Version, Author, Description
This commit is contained in:
Steffen Schröder 2013-12-03 22:21:17 +01:00
parent 35a7232894
commit 6c247f0519
8 changed files with 247 additions and 63 deletions

View File

@ -5,39 +5,50 @@ namespace ManiaControl\Plugins;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
/** /**
* Plugin parent class * Interface for ManiaControl Plugins
* *
* @author steeffeen & kremsy * @author steeffeen & kremsy
*/ */
abstract class Plugin { interface Plugin {
/** /**
* Plugin Metadata * Constants
*/ */
public static $name = 'undefined'; const PLUGIN_INTERFACE = __CLASS__;
public static $version = 'undefined';
public static $author = 'undefined';
public static $description = 'undefined';
/**
* Protected properties
*/
protected $maniaControl = null;
/** /**
* Create a new plugin * Create a new plugin
* *
* @param \ManiaControl\ManiaControl $maniaControl * @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 * @return string
*/ */
public static final function getClass() { public static function getName();
return __CLASS__;
} /**
* 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();
} }
?> ?>

View File

@ -150,7 +150,7 @@ class PluginManager {
$classesAfter = get_declared_classes(); $classesAfter = get_declared_classes();
$newClasses = array_diff($classesAfter, $classesBefore); $newClasses = array_diff($classesAfter, $classesBefore);
foreach ($newClasses as $className) { foreach ($newClasses as $className) {
if (!is_subclass_of($className, Plugin::getClass())) { if (!in_array(Plugin::PLUGIN_INTERFACE, class_implements($className))) {
continue; continue;
} }
array_push($this->pluginClasses, $className); array_push($this->pluginClasses, $className);

View File

@ -10,11 +10,11 @@ use ManiaControl\Plugins\Plugin;
* *
* @author steeffeen * @author steeffeen
*/ */
class ChatlogPlugin extends Plugin implements CallbackListener { class ChatlogPlugin implements CallbackListener, Plugin {
/** /**
* Constants * Constants
*/ */
const VERSION = '1.0'; const VERSION = 1.0;
const SETTING_FOLDERNAME = 'Log-Folder Name'; const SETTING_FOLDERNAME = 'Log-Folder Name';
const SETTING_FILENAME = 'Log-File Name'; const SETTING_FILENAME = 'Log-File Name';
const SETTING_USEPID = 'Use Process-Id for File Name'; const SETTING_USEPID = 'Use Process-Id for File Name';
@ -28,16 +28,12 @@ class ChatlogPlugin extends Plugin implements CallbackListener {
/** /**
* Constuct chatlog plugin * Constuct chatlog plugin
*
* @param ManiaControl $maniaControl
*/ */
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->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 // Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_FOLDERNAME, 'logs'); $this->maniaControl->settingManager->initSetting($this, self::SETTING_FOLDERNAME, 'logs');
$this->maniaControl->settingManager->initSetting($this, self::SETTING_FILENAME, 'ChatLog.log'); $this->maniaControl->settingManager->initSetting($this, self::SETTING_FILENAME, 'ChatLog.log');
@ -75,6 +71,38 @@ class ChatlogPlugin extends Plugin implements CallbackListener {
'handlePlayerChatCallback'); '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 * Handle PlayerChat callback
* *

View File

@ -4,19 +4,19 @@ use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Plugins\Plugin;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Plugins\Plugin;
/** /**
* Donation plugin * Donation plugin
* *
* @author steeffeen * @author steeffeen
*/ */
class DonationPlugin extends Plugin implements CallbackListener, CommandListener { class DonationPlugin implements CallbackListener, CommandListener, Plugin {
/** /**
* Constants * Constants
*/ */
const VERSION = '1.0'; const VERSION = 1.0;
const SETTING_ANNOUNCE_SERVERDONATION = 'Enable Server-Donation Announcements'; const SETTING_ANNOUNCE_SERVERDONATION = 'Enable Server-Donation Announcements';
/** /**
@ -32,12 +32,6 @@ class DonationPlugin extends Plugin implements CallbackListener, CommandListener
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->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 // Register for commands
$this->maniaControl->commandManager->registerCommandListener('donate', $this, 'command_Donate'); $this->maniaControl->commandManager->registerCommandListener('donate', $this, 'command_Donate');
$this->maniaControl->commandManager->registerCommandListener('/pay', $this, 'command_Pay'); $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'); $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 * Handle /donate command
* *

View File

@ -9,11 +9,11 @@ use ManiaControl\Plugins\Plugin;
* *
* @author steeffeen * @author steeffeen
*/ */
class EndurancePlugin extends Plugin implements CallbackListener { class EndurancePlugin implements CallbackListener, Plugin {
/** /**
* Constants * Constants
*/ */
const VERSION = '1.0'; const VERSION = 1.0;
const CB_CHECKPOINT = 'Endurance.Checkpoint'; const CB_CHECKPOINT = 'Endurance.Checkpoint';
/** /**
@ -30,18 +30,44 @@ class EndurancePlugin extends Plugin implements CallbackListener {
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->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 // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'callback_OnInit'); $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->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'callback_BeginMap');
$this->maniaControl->callbackManager->registerScriptCallbackListener(self::CB_CHECKPOINT, $this, 'callback_Checkpoint'); $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 * Handle ManiaControl OnInit callback
* *

View File

@ -19,11 +19,11 @@ use FML\Controls\Gauge;
* *
* @author steeffeen * @author steeffeen
*/ */
class KarmaPlugin extends Plugin implements CallbackListener { class KarmaPlugin implements CallbackListener, Plugin {
/** /**
* Constants * Constants
*/ */
const VERSION = '1.0'; const VERSION = 1.0;
const MLID_KARMA = 'KarmaPlugin.MLID'; const MLID_KARMA = 'KarmaPlugin.MLID';
const TABLE_KARMA = 'mc_karma'; const TABLE_KARMA = 'mc_karma';
const SETTING_AVAILABLE_VOTES = 'Available Votes (X-Y: Comma separated)'; 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_WIDTH = 'Widget-Size: Width';
const SETTING_WIDGET_HEIGHT = 'Widget-Size: Height'; 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 properties
*/ */
@ -47,12 +55,6 @@ class KarmaPlugin extends Plugin implements CallbackListener {
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->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 // Init database
$this->initTables(); $this->initTables();
@ -73,6 +75,38 @@ class KarmaPlugin extends Plugin implements CallbackListener {
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handlePlayerChat'); $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 * Handle ManiaControl 1 Second callback
* *

View File

@ -20,11 +20,11 @@ use FML\Controls\Labels\Label_Text;
* *
* @author steeffeen * @author steeffeen
*/ */
class LocalRecordsPlugin extends Plugin implements CallbackListener { class LocalRecordsPlugin implements CallbackListener, Plugin {
/** /**
* Constants * Constants
*/ */
const VERSION = '1.0'; const VERSION = 1.0;
const MLID_RECORDS = 'ml_local_records'; const MLID_RECORDS = 'ml_local_records';
const TABLE_RECORDS = 'mc_localrecords'; const TABLE_RECORDS = 'mc_localrecords';
const SETTING_WIDGET_TITLE = 'Widget Title'; 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 * Handle ManiaControl init
* *

View File

@ -12,11 +12,11 @@ use ManiaControl\Plugins\Plugin;
* *
* @author steeffeen * @author steeffeen
*/ */
class ObstaclePlugin extends Plugin implements CallbackListener, CommandListener { class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
/** /**
* Constants * Constants
*/ */
const VERSION = '1.0'; const VERSION = 1.0;
const CB_JUMPTO = 'Obstacle.JumpTo'; const CB_JUMPTO = 'Obstacle.JumpTo';
const SCB_ONFINISH = 'OnFinish'; const SCB_ONFINISH = 'OnFinish';
const SCB_ONCHECKPOINT = 'OnCheckpoint'; const SCB_ONCHECKPOINT = 'OnCheckpoint';
@ -28,12 +28,6 @@ class ObstaclePlugin extends Plugin implements CallbackListener, CommandListener
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->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 // Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_JUMPTOAUTHLEVEL, $this->maniaControl->settingManager->initSetting($this, self::SETTING_JUMPTOAUTHLEVEL,
AuthenticationManager::AUTH_LEVEL_OPERATOR); 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'); $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 * Handle JumpTo command
* *
@ -56,7 +82,7 @@ class ObstaclePlugin extends Plugin implements CallbackListener, CommandListener
$authLevel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_JUMPTOAUTHLEVEL); $authLevel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_JUMPTOAUTHLEVEL);
if (!$this->maniaControl->authenticationManager->checkRight($player, $authLevel)) { if (!$this->maniaControl->authenticationManager->checkRight($player, $authLevel)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return false; return;
} }
// Send jump callback // Send jump callback
$params = explode(' ', $chatCallback[1][2], 2); $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)) { if (!$this->maniaControl->client->query('TriggerModeScriptEvent', self::CB_JUMPTO, $param)) {
trigger_error("Couldn't send jump callback for '{$player->login}'. " . $this->maniaControl->getClientErrorText()); 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 * @param array $callback
*/ */
public function callback_OnCheckpoint(array $callback) { public function callback_OnCheckpoint(array $callback) {
// TODO: check back with trackmania callback format
return;
$data = json_decode($callback[1]); $data = json_decode($callback[1]);
$player = $this->maniaControl->playerManager->getPlayer($data->Player->Login); $player = $this->maniaControl->playerManager->getPlayer($data->Player->Login);
if (!$player) { if (!$player) {