updated depreced callbacks

This commit is contained in:
kremsy 2014-04-28 20:50:38 +02:00 committed by Steffen Schröder
parent 429702d2e6
commit 09e7a1517c
10 changed files with 282 additions and 298 deletions

View File

@ -13,6 +13,7 @@ use FML\Script\Script;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Maps\Map; use ManiaControl\Maps\Map;
use ManiaControl\Maps\MapManager; use ManiaControl\Maps\MapManager;
@ -55,7 +56,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'onInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'onInit');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'onBeginMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'onBeginMap');
$this->maniaControl->settingManager->initSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN, true); $this->maniaControl->settingManager->initSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN, true);
$this->initTables(); $this->initTables();

View File

@ -16,6 +16,7 @@ use FML\ManiaLink;
use FML\Script\Features\Paging; use FML\Script\Features\Paging;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\ColorUtil; use ManiaControl\ColorUtil;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
@ -73,7 +74,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->maniaControl->callbackManager->registerCallbackListener(MapQueue::CB_MAPQUEUE_CHANGED, $this, 'updateWidgetQueue'); $this->maniaControl->callbackManager->registerCallbackListener(MapQueue::CB_MAPQUEUE_CHANGED, $this, 'updateWidgetQueue');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_MAPS_UPDATED, $this, 'updateWidget'); $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_MAPS_UPDATED, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_KARMA_UPDATED, $this, 'updateWidget'); $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_KARMA_UPDATED, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'updateWidget'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'updateWidget');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CHECK_UPDATE, $this, 'checkUpdates'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CHECK_UPDATE, $this, 'checkUpdates');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLEAR_MAPQUEUE, $this, 'clearMapQueue'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLEAR_MAPQUEUE, $this, 'clearMapQueue');

View File

@ -5,6 +5,7 @@ namespace ManiaControl\Maps;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
@ -50,8 +51,8 @@ class MapQueue implements CallbackListener, CommandListener {
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'endMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'endMap');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'beginMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'beginMap');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit');
// Init settings // Init settings

View File

@ -10,12 +10,12 @@ use FML\ManiaLink;
use FML\Script\Features\Paging; use FML\Script\Features\Paging;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Maps\MapManager;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin; use ManiaControl\Plugins\Plugin;
@ -101,8 +101,8 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINEHEIGHT, 4); $this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINEHEIGHT, 4);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINESCOUNT, 12); $this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINESCOUNT, 12);
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleBeginMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'handleMapEnd'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleMapEnd');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpoint'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpoint');
@ -329,7 +329,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
//var_dump($data); //var_dump($data);
$content = $this->encode_request(self::DEDIMANIA_SETCHALLENGETIMES, $data); $content = $this->encode_request(self::DEDIMANIA_SETCHALLENGETIMES, $data);
$self = $this; $self = $this;
$maniaControl = $this->maniaControl; $maniaControl = $this->maniaControl;
$this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$self, &$maniaControl) { $this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$self, &$maniaControl) {
if ($error != '') { if ($error != '') {
@ -469,9 +469,11 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
// Only improved time // Only improved time
$improvement = 'improved his/her'; $improvement = 'improved his/her';
} }
$message = '$390$<$fff' . $player->nickname . '$> ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Dedimania Record: $<$fff' . Formatter::formatTime($newRecord->best).'$>'; $message = '$390$<$fff' . $player->nickname . '$> ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Dedimania Record: $<$fff' . Formatter::formatTime($newRecord->best) . '$>';
if(!$oldRecord->nullRecord) $message .= ' ($<$ff0'.$oldRecord->rank.'.$> $<$fff-'.Formatter::formatTime(($oldRecord->best-$time)).'$>)'; if (!$oldRecord->nullRecord) {
$this->maniaControl->chat->sendInformation($message.'!'); $message .= ' ($<$ff0' . $oldRecord->rank . '.$> $<$fff-' . Formatter::formatTime(($oldRecord->best - $time)) . '$>)';
}
$this->maniaControl->chat->sendInformation($message . '!');
$this->updateManialink = true; $this->updateManialink = true;
} }
@ -503,8 +505,8 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
//create manialink //create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$script = $maniaLink->getScript(); $script = $maniaLink->getScript();
$paging = new Paging(); $paging = new Paging();
$script->addFeature($paging); $script->addFeature($paging);
// Main frame // Main frame
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging); $frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging);
@ -537,7 +539,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
} }
array_push($pageFrames, $pageFrame); array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10; $y = $height / 2 - 10;
$paging->addPage($pageFrame); $paging->addPage($pageFrame);
} }
$recordFrame = new Frame(); $recordFrame = new Frame();
@ -970,7 +972,7 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
} else if ($scriptName == 'TimeAttack' || $scriptName == 'Laps' || $scriptName == 'TeamAttack' || $scriptName == 'TimeAttackPlus') { } else if ($scriptName == 'TimeAttack' || $scriptName == 'Laps' || $scriptName == 'TeamAttack' || $scriptName == 'TimeAttackPlus') {
return 'TA'; return 'TA';
} }
break; break;
} }
case 1: case 1:
case 3: case 3:

View File

@ -2,6 +2,7 @@
namespace steeffeen; namespace steeffeen;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
@ -50,7 +51,7 @@ class EndurancePlugin implements CallbackListener, Plugin {
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'callback_OnInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'callback_OnInit');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'callback_BeginMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'callback_BeginMap');
$this->maniaControl->callbackManager->registerScriptCallbackListener(self::CB_CHECKPOINT, $this, 'callback_Checkpoint'); $this->maniaControl->callbackManager->registerScriptCallbackListener(self::CB_CHECKPOINT, $this, 'callback_Checkpoint');
return true; return true;

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,7 @@ use FML\Script\Features\Paging;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Settings\SettingManager; use ManiaControl\Settings\SettingManager;
@ -96,7 +97,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
// Register for callbacks // Register for callbacks
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000); $this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleMapBegin'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleMapBegin');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERFINISH, $this, 'handlePlayerFinish'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERFINISH, $this, 'handlePlayerFinish');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpoint'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpoint');

View File

@ -7,11 +7,11 @@ use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink; use FML\ManiaLink;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Maps\MapManager;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin; use ManiaControl\Plugins\Plugin;
@ -30,11 +30,11 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
/** /**
* Constants * Constants
*/ */
const ID = 22; const ID = 22;
const VERSION = 0.1; const VERSION = 0.1;
const ML_ID = 'Queue.Widget'; const ML_ID = 'Queue.Widget';
const ML_ADDTOQUEUE = 'Queue.Add'; const ML_ADDTOQUEUE = 'Queue.Add';
const ML_REMOVEFROMQUEUE = 'Queue.Remove'; const ML_REMOVEFROMQUEUE = 'Queue.Remove';
const QUEUE_MAX = 'Maximum number in the queue'; const QUEUE_MAX = 'Maximum number in the queue';
const QUEUE_WIDGET_POS_X = 'X position of the widget'; const QUEUE_WIDGET_POS_X = 'X position of the widget';
@ -50,7 +50,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
private $queue = array(); private $queue = array();
private $spectators = array(); private $spectators = array();
private $showPlay = array(); private $showPlay = array();
private $maxPlayers = 0; private $maxPlayers = 0;
/** /**
* Prepares the Plugin * Prepares the Plugin
@ -75,7 +75,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERINFOCHANGED, $this, 'handlePlayerInfoChanged'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERINFOCHANGED, $this, 'handlePlayerInfoChanged');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleBeginMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ML_ADDTOQUEUE, $this, 'handleManiaLinkAnswerAdd'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ML_ADDTOQUEUE, $this, 'handleManiaLinkAnswerAdd');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ML_REMOVEFROMQUEUE, $this, 'handleManiaLinkAnswerRemove'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ML_REMOVEFROMQUEUE, $this, 'handleManiaLinkAnswerRemove');
@ -86,7 +86,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$this->maniaControl->settingManager->initSetting($this, self::QUEUE_CHATMESSAGES, true); $this->maniaControl->settingManager->initSetting($this, self::QUEUE_CHATMESSAGES, true);
foreach($this->maniaControl->playerManager->getPlayers() as $player) { foreach($this->maniaControl->playerManager->getPlayers() as $player) {
if($player->isSpectator) { if ($player->isSpectator) {
$this->spectators[$player->login] = $player->login; $this->spectators[$player->login] = $player->login;
$this->maniaControl->client->forceSpectator($player->login, 1); $this->maniaControl->client->forceSpectator($player->login, 1);
$this->showJoinQueueWidget($player); $this->showJoinQueueWidget($player);
@ -168,15 +168,15 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* @param Player $player * @param Player $player
*/ */
public function handlePlayerConnect(Player $player) { public function handlePlayerConnect(Player $player) {
$maxPlayers = $this->maniaControl->client->getMaxPlayers(); $maxPlayers = $this->maniaControl->client->getMaxPlayers();
$this->maxPlayers = $maxPlayers['CurrentValue']; $this->maxPlayers = $maxPlayers['CurrentValue'];
if($player->isSpectator) { if ($player->isSpectator) {
$this->spectators[$player->login] = $player->login; $this->spectators[$player->login] = $player->login;
$this->maniaControl->client->forceSpectator($player->login, 1); $this->maniaControl->client->forceSpectator($player->login, 1);
$this->showJoinQueueWidget($player); $this->showJoinQueueWidget($player);
} else { } else {
if(count($this->queue) != 0) { if (count($this->queue) != 0) {
$this->maniaControl->client->forceSpectator($player->login, 1); $this->maniaControl->client->forceSpectator($player->login, 1);
$this->spectators[$player->login] = $player->login; $this->spectators[$player->login] = $player->login;
$this->showJoinQueueWidget($player); $this->showJoinQueueWidget($player);
@ -190,10 +190,10 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* @param Player $player * @param Player $player
*/ */
public function handlePlayerDisconnect(Player $player) { public function handlePlayerDisconnect(Player $player) {
$maxPlayers = $this->maniaControl->client->getMaxPlayers(); $maxPlayers = $this->maniaControl->client->getMaxPlayers();
$this->maxPlayers = $maxPlayers['CurrentValue']; $this->maxPlayers = $maxPlayers['CurrentValue'];
if(isset($this->spectators[$player->login])) { if (isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]); unset($this->spectators[$player->login]);
} }
$this->removePlayerFromQueue($player->login); $this->removePlayerFromQueue($player->login);
@ -209,27 +209,27 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$login = $callback[1][0]['Login']; $login = $callback[1][0]['Login'];
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
if(!is_null($player)) { if (!is_null($player)) {
if($player->isSpectator) { if ($player->isSpectator) {
if(!isset($this->spectators[$player->login])) { if (!isset($this->spectators[$player->login])) {
$this->maniaControl->client->forceSpectator($player->login, 1); $this->maniaControl->client->forceSpectator($player->login, 1);
$this->spectators[$player->login] = $player->login; $this->spectators[$player->login] = $player->login;
$this->showJoinQueueWidget($player); $this->showJoinQueueWidget($player);
} }
} else { } else {
$this->removePlayerFromQueue($player->login); $this->removePlayerFromQueue($player->login);
if(isset($this->spectators[$player->login])) { if (isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]); unset($this->spectators[$player->login]);
} }
$found = false; $found = false;
foreach($this->showPlay as $showPlay) { foreach($this->showPlay as $showPlay) {
if($showPlay['player']->login == $player->login) { if ($showPlay['player']->login == $player->login) {
$found = true; $found = true;
} }
} }
if(!$found) { if (!$found) {
$this->hideQueueWidget($player); $this->hideQueueWidget($player);
} }
} }
@ -240,7 +240,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* Function called on every second. * Function called on every second.
*/ */
public function handleEverySecond() { public function handleEverySecond() {
if($this->maxPlayers > (count($this->maniaControl->playerManager->players) - count($this->spectators))) { if ($this->maxPlayers > (count($this->maniaControl->playerManager->players) - count($this->spectators))) {
$this->moveFirstPlayerToPlay(); $this->moveFirstPlayerToPlay();
} }
@ -250,22 +250,22 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
} }
foreach($this->showPlay as $showPlay) { foreach($this->showPlay as $showPlay) {
if(($showPlay['time'] + 5) < time()) { if (($showPlay['time'] + 5) < time()) {
$this->hideQueueWidget($showPlay['player']); $this->hideQueueWidget($showPlay['player']);
unset($this->showPlay[$showPlay['player']->login]); unset($this->showPlay[$showPlay['player']->login]);
} }
} }
} }
/** /**
* Checks for being of new map to retrieve maximum number of players. * Checks for being of new map to retrieve maximum number of players.
* *
* @param $currentMap * @param $currentMap
*/ */
public function handleBeginMap($currentMap) { public function handleBeginMap($currentMap) {
$maxPlayers = $this->maniaControl->client->getMaxPlayers(); $maxPlayers = $this->maniaControl->client->getMaxPlayers();
$this->maxPlayers = $maxPlayers['CurrentValue']; $this->maxPlayers = $maxPlayers['CurrentValue'];
} }
/** /**
* Function handling the click of the widget to add them to the queue. * Function handling the click of the widget to add them to the queue.
@ -293,7 +293,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* Function used to move the first queued player to the * Function used to move the first queued player to the
*/ */
private function moveFirstPlayerToPlay() { private function moveFirstPlayerToPlay() {
if(count($this->queue) > 0) { if (count($this->queue) > 0) {
$firstPlayer = $this->maniaControl->playerManager->getPlayer($this->queue[0]->login); $firstPlayer = $this->maniaControl->playerManager->getPlayer($this->queue[0]->login);
$this->forcePlayerToPlay($firstPlayer); $this->forcePlayerToPlay($firstPlayer);
} }
@ -305,9 +305,11 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* @param Player $player * @param Player $player
*/ */
private function forcePlayerToPlay(Player $player) { private function forcePlayerToPlay(Player $player) {
if($this->maniaControl->client->getServerPassword() != false && $this->maniaControl->settingManager->getSetting($this, self::QUEUE_ACTIVE_ON_PASS) == false) return; if ($this->maniaControl->client->getServerPassword() != false && $this->maniaControl->settingManager->getSetting($this, self::QUEUE_ACTIVE_ON_PASS) == false) {
return;
}
if($this->maxPlayers > (count($this->maniaControl->playerManager->players) - count($this->spectators))) { if ($this->maxPlayers > (count($this->maniaControl->playerManager->players) - count($this->spectators))) {
try { try {
$this->maniaControl->client->forceSpectator($player->login, 2); $this->maniaControl->client->forceSpectator($player->login, 2);
} catch(Exception $e) { } catch(Exception $e) {
@ -325,7 +327,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$teams = array(); $teams = array();
/** @var Player $playerObj */ /** @var Player $playerObj */
foreach($this->maniaControl->playerManager->players as $playerObj) { foreach($this->maniaControl->playerManager->players as $playerObj) {
if(!isset($teams[$playerObj->teamId])) { if (!isset($teams[$playerObj->teamId])) {
$teams[$playerObj->teamId] = 1; $teams[$playerObj->teamId] = 1;
} else { } else {
$teams[$playerObj->teamId]++; $teams[$playerObj->teamId]++;
@ -335,21 +337,21 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$smallestTeam = null; $smallestTeam = null;
$smallestSize = 999; $smallestSize = 999;
foreach($teams as $team => $size) { foreach($teams as $team => $size) {
if($size < $smallestSize) { if ($size < $smallestSize) {
$smallestTeam = $team; $smallestTeam = $team;
$smallestSize = $size; $smallestSize = $size;
} }
} }
try { try {
if($smallestTeam != -1) { if ($smallestTeam != -1) {
$this->maniaControl->client->forcePlayerTeam($player->login, $smallestTeam); $this->maniaControl->client->forcePlayerTeam($player->login, $smallestTeam);
} }
} catch(Exception $e) { } catch(Exception $e) {
// TODO: only possible valid exceptions should be "wrong login" or "not in team mode" - throw others (like connection error) // TODO: only possible valid exceptions should be "wrong login" or "not in team mode" - throw others (like connection error)
} }
if(isset($this->spectators[$player->login])) { if (isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]); unset($this->spectators[$player->login]);
} }
$this->removePlayerFromQueue($player->login); $this->removePlayerFromQueue($player->login);
@ -366,21 +368,23 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* @return bool * @return bool
*/ */
private function addPlayerToQueue(Player $player) { private function addPlayerToQueue(Player $player) {
if($this->maniaControl->client->getServerPassword() != false && $this->maniaControl->settingManager->getSetting($this, self::QUEUE_ACTIVE_ON_PASS) == false) return false; if ($this->maniaControl->client->getServerPassword() != false && $this->maniaControl->settingManager->getSetting($this, self::QUEUE_ACTIVE_ON_PASS) == false) {
return false;
}
foreach($this->queue as $queuedPlayer) { foreach($this->queue as $queuedPlayer) {
if($queuedPlayer->login == $player->login) { if ($queuedPlayer->login == $player->login) {
$this->maniaControl->chat->sendError('You\'re already in the queue!', $player->login); $this->maniaControl->chat->sendError('You\'re already in the queue!', $player->login);
return false; return false;
} }
} }
if($this->maniaControl->settingManager->getSetting($this, self::QUEUE_MAX) > count($this->queue)) { if ($this->maniaControl->settingManager->getSetting($this, self::QUEUE_MAX) > count($this->queue)) {
$this->queue[count($this->queue)] = $player; $this->queue[count($this->queue)] = $player;
$this->sendChatMessage('$<$fff' . $player->nickname . '$> just joined the queue!'); $this->sendChatMessage('$<$fff' . $player->nickname . '$> just joined the queue!');
} }
return true; return true;
} }
/** /**
@ -392,7 +396,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$count = 0; $count = 0;
$newQueue = array(); $newQueue = array();
foreach($this->queue as $queuePlayer) { foreach($this->queue as $queuePlayer) {
if($queuePlayer->login != $login) { if ($queuePlayer->login != $login) {
$newQueue[$count] = $queuePlayer; $newQueue[$count] = $queuePlayer;
$count++; $count++;
} }
@ -407,8 +411,8 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* @param $message * @param $message
*/ */
private function sendChatMessage($message) { private function sendChatMessage($message) {
if($this->maniaControl->settingManager->getSetting($this, self::QUEUE_CHATMESSAGES)) { if ($this->maniaControl->settingManager->getSetting($this, self::QUEUE_CHATMESSAGES)) {
$this->maniaControl->chat->sendChat('$z$s$090[Queue] '.$message); $this->maniaControl->chat->sendChat('$z$s$090[Queue] ' . $message);
} }
} }
@ -465,17 +469,17 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$inQueue = false; $inQueue = false;
foreach($this->queue as $queuedPlayer) { foreach($this->queue as $queuedPlayer) {
if($queuedPlayer->login == $player->login) { if ($queuedPlayer->login == $player->login) {
$inQueue = true; $inQueue = true;
} }
} }
if($inQueue) { if ($inQueue) {
$message = '$fff$sYou\'re in the queue (click to unqueue).'; $message = '$fff$sYou\'re in the queue (click to unqueue).';
$position = 0; $position = 0;
foreach(array_values($this->queue) as $i => $queuePlayer) { foreach(array_values($this->queue) as $i => $queuePlayer) {
if($player->login == $queuePlayer->login) { if ($player->login == $queuePlayer->login) {
$position = ($i + 1); $position = ($i + 1);
} }
} }
@ -486,7 +490,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$statusLabel->setAction(self::ML_REMOVEFROMQUEUE); $statusLabel->setAction(self::ML_REMOVEFROMQUEUE);
$cameraQuad->setAction(self::ML_REMOVEFROMQUEUE); $cameraQuad->setAction(self::ML_REMOVEFROMQUEUE);
} else { } else {
if(count($this->queue) < $max_queue) { if (count($this->queue) < $max_queue) {
$message = '$0ff$sClick to join spectator waiting list.'; $message = '$0ff$sClick to join spectator waiting list.';
$messageLabel->setAction(self::ML_ADDTOQUEUE); $messageLabel->setAction(self::ML_ADDTOQUEUE);
$backgroundQuad->setAction(self::ML_ADDTOQUEUE); $backgroundQuad->setAction(self::ML_ADDTOQUEUE);

View File

@ -1,6 +1,7 @@
<?php <?php
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Maps\Map; use ManiaControl\Maps\Map;
@ -92,7 +93,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
//Register CallbackListeners //Register CallbackListeners
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'handleEndMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleEndMap');
//Register CommandListener //Register CommandListener
$this->maniaControl->commandManager->registerCommandListener('rank', $this, 'command_showRank', false); $this->maniaControl->commandManager->registerCommandListener('rank', $this, 'command_showRank', false);

View File

@ -11,6 +11,7 @@ use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink; use FML\ManiaLink;
use FML\Script\Script; use FML\Script\Script;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
@ -101,8 +102,8 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
$this->maniaControl->manialinkManager->customUIManager->setChallengeInfoVisible(false); $this->maniaControl->manialinkManager->customUIManager->setChallengeInfoVisible(false);
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleOnBeginMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleOnBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'handleOnEndMap'); $this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleOnEndMap');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');