improved PHPDoc & applied common style
This commit is contained in:
@ -2,13 +2,12 @@
|
||||
|
||||
namespace steeffeen;
|
||||
|
||||
use ManiaControl\Callbacks\Callbacks;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Callbacks\Callbacks;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Maps\Map;
|
||||
use ManiaControl\Plugins\Plugin;
|
||||
use ManiaControl\Maps\MapManager;
|
||||
|
||||
/**
|
||||
* Plugin for the TM Game Mode 'Endurance' by TGYoshi
|
||||
@ -16,56 +15,32 @@ use ManiaControl\Maps\MapManager;
|
||||
* @author steeffeen
|
||||
*/
|
||||
class EndurancePlugin implements CallbackListener, Plugin {
|
||||
/**
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const ID = 25;
|
||||
const VERSION = 0.2;
|
||||
const ID = 25;
|
||||
const VERSION = 0.2;
|
||||
const NAME = 'Endurance Plugin';
|
||||
const AUTHOR = 'steeffeen';
|
||||
const CB_CHECKPOINT = 'Endurance.Checkpoint';
|
||||
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
* Private Properties
|
||||
*/
|
||||
/** @var maniaControl $maniaControl */
|
||||
/** @var ManiaControl $maniaControl */
|
||||
private $maniaControl = null;
|
||||
/** @var Map $currentMap */
|
||||
private $currentMap = null;
|
||||
private $playerLapTimes = array();
|
||||
|
||||
/**
|
||||
* Prepares the Plugin
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
* @return mixed
|
||||
* @see \ManiaControl\Plugins\Plugin::prepare()
|
||||
*/
|
||||
public static function prepare(ManiaControl $maniaControl) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::load()
|
||||
*/
|
||||
public function load(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'callback_OnInit');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'callback_BeginMap');
|
||||
$this->maniaControl->callbackManager->registerScriptCallbackListener(self::CB_CHECKPOINT, $this, 'callback_Checkpoint');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::unload()
|
||||
*/
|
||||
public function unload() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::getId()
|
||||
*/
|
||||
public static function getId() {
|
||||
@ -73,15 +48,13 @@ class EndurancePlugin implements CallbackListener, Plugin {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::getName()
|
||||
*/
|
||||
public static function getName() {
|
||||
return 'Endurance Plugin';
|
||||
return self::NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::getVersion()
|
||||
*/
|
||||
public static function getVersion() {
|
||||
@ -89,28 +62,46 @@ class EndurancePlugin implements CallbackListener, Plugin {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::getAuthor()
|
||||
*/
|
||||
public static function getAuthor() {
|
||||
return 'steeffeen';
|
||||
return self::AUTHOR;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::getDescription()
|
||||
*/
|
||||
public static function getDescription() {
|
||||
return "Plugin enabling Support for the TM Game Mode 'Endurance' by TGYoshi.";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::load()
|
||||
*/
|
||||
public function load(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'callback_OnInit');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'callback_BeginMap');
|
||||
$this->maniaControl->callbackManager->registerScriptCallbackListener(self::CB_CHECKPOINT, $this, 'callback_Checkpoint');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::unload()
|
||||
*/
|
||||
public function unload() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ManiaControl OnInit callback
|
||||
*
|
||||
* @param array $callback
|
||||
* @param array $callback
|
||||
*/
|
||||
public function callback_OnInit(array $callback) {
|
||||
$this->currentMap = $this->maniaControl->mapManager->getCurrentMap();
|
||||
$this->currentMap = $this->maniaControl->mapManager->getCurrentMap();
|
||||
$this->playerLapTimes = array();
|
||||
}
|
||||
|
||||
@ -120,14 +111,14 @@ class EndurancePlugin implements CallbackListener, Plugin {
|
||||
* @param Map $map
|
||||
*/
|
||||
public function callback_BeginMap(Map $map) {
|
||||
$this->currentMap = $map;
|
||||
$this->currentMap = $map;
|
||||
$this->playerLapTimes = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Endurance Checkpoint callback
|
||||
*
|
||||
* @param array $callback
|
||||
* @param array $callback
|
||||
*/
|
||||
public function callback_Checkpoint(array $callback) {
|
||||
$callbackData = json_decode($callback[1]);
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
namespace steeffeen;
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Admin\AuthenticationManager;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Plugins\Plugin;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
@ -17,63 +17,32 @@ use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
* @author steeffeen
|
||||
*/
|
||||
class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
|
||||
/**
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const ID = 24;
|
||||
const VERSION = 0.2;
|
||||
const CB_JUMPTO = 'Obstacle.JumpTo';
|
||||
const SCB_ONFINISH = 'OnFinish';
|
||||
const SCB_ONCHECKPOINT = 'OnCheckpoint';
|
||||
const ID = 24;
|
||||
const VERSION = 0.2;
|
||||
const NAME = 'Obstacle Plugin';
|
||||
const AUTHOR = 'steeffeen';
|
||||
const CB_JUMPTO = 'Obstacle.JumpTo';
|
||||
const SCB_ONFINISH = 'OnFinish';
|
||||
const SCB_ONCHECKPOINT = 'OnCheckpoint';
|
||||
const SETTING_JUMPTOAUTHLEVEL = 'Authentication level for JumpTo commands';
|
||||
|
||||
|
||||
/**
|
||||
* Private Properties
|
||||
*/
|
||||
/**
|
||||
* @var maniaControl $maniaControl
|
||||
*/
|
||||
/** @var ManiaControl $maniaControl */
|
||||
private $maniaControl = null;
|
||||
|
||||
/**
|
||||
* Prepares the Plugin
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
* @return mixed
|
||||
* @see \ManiaControl\Plugins\Plugin::prepare()
|
||||
*/
|
||||
public static function prepare(ManiaControl $maniaControl) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::load()
|
||||
*/
|
||||
public function load(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Init settings
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_JUMPTOAUTHLEVEL, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||
|
||||
// Register for commands
|
||||
$this->maniaControl->commandManager->registerCommandListener('jumpto', $this, 'command_JumpTo');
|
||||
|
||||
// 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() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::getId()
|
||||
*/
|
||||
public static function getId() {
|
||||
@ -81,15 +50,13 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::getName()
|
||||
*/
|
||||
public static function getName() {
|
||||
return 'Obstacle Plugin';
|
||||
return self::NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::getVersion()
|
||||
*/
|
||||
public static function getVersion() {
|
||||
@ -97,25 +64,48 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::getAuthor()
|
||||
*/
|
||||
public static function getAuthor() {
|
||||
return 'steeffeen';
|
||||
return self::AUTHOR;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \ManiaControl\Plugins\Plugin::getDescription()
|
||||
*/
|
||||
public static function getDescription() {
|
||||
return "Plugin offering CP Jumping and Local Records Support for the ShootManie Gamemode 'Obstacle'.";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Plugins\Plugin::load()
|
||||
*/
|
||||
public function load(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Init settings
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_JUMPTOAUTHLEVEL, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||
|
||||
// Register for commands
|
||||
$this->maniaControl->commandManager->registerCommandListener('jumpto', $this, 'command_JumpTo');
|
||||
|
||||
// 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() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle JumpTo command
|
||||
*
|
||||
* @param array $chatCallback
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
@ -127,11 +117,10 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
|
||||
}
|
||||
// Send jump callback
|
||||
$params = explode(' ', $chatCallback[1][2], 2);
|
||||
$param = $player->login . ";" . $params[1] . ";";
|
||||
$param = $player->login . ";" . $params[1] . ";";
|
||||
try {
|
||||
$this->maniaControl->client->triggerModeScriptEvent(self::CB_JUMPTO, $param);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
if ($e->getMessage() == 'Not in script mode.') {
|
||||
trigger_error("Couldn't send jump callback for '{$player->login}'. " . $e->getMessage());
|
||||
return;
|
||||
@ -146,7 +135,7 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
|
||||
* @param array $callback
|
||||
*/
|
||||
public function callback_OnFinish(array $callback) {
|
||||
$data = json_decode($callback[1]);
|
||||
$data = json_decode($callback[1]);
|
||||
$player = $this->maniaControl->playerManager->getPlayer($data->Player->Login);
|
||||
if (!$player) {
|
||||
return;
|
||||
@ -154,8 +143,7 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
|
||||
$time = $data->Run->Time;
|
||||
// Trigger trackmania player finish callback
|
||||
$finishCallback = array($player->pid, $player->login, $time);
|
||||
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERFINISH,
|
||||
array(CallbackManager::CB_TM_PLAYERFINISH, $finishCallback));
|
||||
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERFINISH, array(CallbackManager::CB_TM_PLAYERFINISH, $finishCallback));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,15 +152,14 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
|
||||
* @param array $callback
|
||||
*/
|
||||
public function callback_OnCheckpoint(array $callback) {
|
||||
$data = json_decode($callback[1]);
|
||||
$data = json_decode($callback[1]);
|
||||
$player = $this->maniaControl->playerManager->getPlayer($data->Player->Login);
|
||||
$time = $data->Run->Time;
|
||||
$time = $data->Run->Time;
|
||||
if (!$player || $time <= 0) {
|
||||
return;
|
||||
}
|
||||
// Trigger Trackmania player checkpoint callback
|
||||
$checkpointCallback = array($player->pid, $player->login, $time, 0, 0);
|
||||
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERCHECKPOINT,
|
||||
array(CallbackManager::CB_TM_PLAYERCHECKPOINT, $checkpointCallback));
|
||||
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERCHECKPOINT, array(CallbackManager::CB_TM_PLAYERCHECKPOINT, $checkpointCallback));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user