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\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\ManiaControl;
use ManiaControl\Maps\Map;
use ManiaControl\Maps\MapManager;
@ -55,7 +56,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
// Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$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->initTables();

View File

@ -16,6 +16,7 @@ use FML\ManiaLink;
use FML\Script\Features\Paging;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\ColorUtil;
use ManiaControl\Formatter;
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(MapManager::CB_MAPS_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_CLEAR_MAPQUEUE, $this, 'clearMapQueue');

View File

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

View File

@ -10,12 +10,12 @@ use FML\ManiaLink;
use FML\Script\Features\Paging;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener;
use ManiaControl\Formatter;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Maps\MapManager;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
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_LINESCOUNT, 12);
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'handleMapEnd');
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleMapEnd');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpoint');
@ -469,9 +469,11 @@ class Dedimania implements CallbackListener, CommandListener, TimerListener, Plu
// Only improved time
$improvement = 'improved his/her';
}
$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)).'$>)';
$this->maniaControl->chat->sendInformation($message.'!');
$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)) . '$>)';
}
$this->maniaControl->chat->sendInformation($message . '!');
$this->updateManialink = true;
}

View File

@ -2,6 +2,7 @@
namespace steeffeen;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\ManiaControl;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
@ -50,7 +51,7 @@ class EndurancePlugin implements CallbackListener, Plugin {
// Register for callbacks
$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');
return true;

View File

@ -9,11 +9,11 @@ use FML\Controls\Quad;
use FML\ManiaLink;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\ColorUtil;
use ManiaControl\ManiaControl;
use ManiaControl\Maps\Map;
use ManiaControl\Maps\MapManager;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin;
@ -62,20 +62,17 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
* Private Properties
*/
/**
*
* @var ManiaControl $maniaControl
*/
private $maniaControl = null;
private $updateManialink = false;
/**
*
* @var ManiaLink $manialink
*/
private $manialink = null;
private $mxKarma = array();
/**
*
* @see \ManiaControl\Plugins\Plugin
*/
public static function prepare(ManiaControl $maniaControl) {
@ -83,13 +80,12 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$maniaControl->settingManager->initSetting(get_class(), self::SETTING_MX_KARMA_IMPORTING, true);
$maniaControl->settingManager->initSetting(get_class(), self::SETTING_WIDGET_DISPLAY_MX, true);
$servers = $maniaControl->server->getAllServers();
foreach ($servers as $server) {
foreach($servers as $server) {
$maniaControl->settingManager->initSetting(get_class(), '$l[http://karma.mania-exchange.com/auth/getapikey?server=' . $server->login . ']MX Karma Code for ' . $server->login . '$l', '');
}
}
/**
*
* @see \ManiaControl\Plugins\Plugin::load()
*/
public function load(ManiaControl $maniaControl) {
@ -109,9 +105,9 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
// Register for callbacks
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'importMxKarmaVotes');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'sendMxKarmaVotes');
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'importMxKarmaVotes');
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'sendMxKarmaVotes');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handlePlayerChat');
$this->maniaControl->callbackManager->registerCallbackListener(SettingManager::CB_SETTINGS_CHANGED, $this, 'updateSettings');
@ -132,7 +128,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
}
/**
*
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
@ -143,7 +138,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
@ -151,7 +145,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
@ -159,7 +152,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
@ -167,7 +159,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
@ -175,7 +166,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {
@ -208,8 +198,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
if ($displayMxKarma && isset($this->mxKarma['session']) && isset($this->mxKarma['voteCount'])) {
$karma = $this->mxKarma['modeVoteAverage'] / 100;
$voteCount = $this->mxKarma['modeVoteCount'];
}
else {
} else {
$karma = $this->getMapKarma($map);
$votes = $this->getMapVotes($map);
$voteCount = $votes['count'];
@ -221,12 +210,10 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
// Update karma gauge & label
/**
*
* @var Gauge $karmaGauge
*/
$karmaGauge = $this->manialink->karmaGauge;
/**
*
* @var Label $karmaLabel
*/
$karmaLabel = $this->manialink->karmaLabel;
@ -236,15 +223,14 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$karmaColor = ColorUtil::floatToStatusColor($karma);
$karmaGauge->setColor($karmaColor . '7');
$karmaLabel->setText(' ' . round($karma * 100.) . '% (' . $voteCount . ')');
}
else {
} else {
$karmaGauge->setRatio(0.);
$karmaGauge->setColor('00fb');
$karmaLabel->setText('-');
}
// Loop players
foreach ($players as $login => $player) {
foreach($players as $login => $player) {
// Get player vote
// TODO: show the player his own vote in some way
// $vote = $this->getPlayerVote($player, $map);
@ -266,7 +252,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
// send Map Karma to MX from previous Map
if (isset($this->mxKarma['map'])) {
$votes = array();
foreach ($this->mxKarma['votes'] as $login => $value) {
foreach($this->mxKarma['votes'] as $login => $value) {
$player = $this->maniaControl->playerManager->getPlayer($login);
array_push($votes, array("login" => $login, "nickname" => $player->rawNickname, "vote" => $value));
}
@ -365,8 +351,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$modeSum = $this->mxKarma["modeVoteCount"] * $this->mxKarma["modeVoteAverage"] + $vote * 100;
$this->mxKarma["modeVoteCount"]++;
}
else {
} else {
$oldVote = $this->mxKarma["votes"][$player->login];
$sum = $this->mxKarma["voteCount"] * $this->mxKarma["voteAverage"] - $oldVote + $vote * 100;
$modeSum = $this->mxKarma["modeVoteCount"] * $this->mxKarma["modeVoteAverage"] - $oldVote + $vote * 100;
@ -554,7 +539,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
}
$votes = array();
$count = 0;
while ($vote = $result->fetch_object()) {
while($vote = $result->fetch_object()) {
$votes[$vote->vote] = $vote;
$count += $vote->count;
}
@ -645,8 +630,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
if ($settingName == 'Enable Karma Widget' && $value == true) {
$this->updateManialink = true;
$this->handle1Second(time());
}
elseif ($settingName == 'Enable Karma Widget' && $value == false) {
} elseif ($settingName == 'Enable Karma Widget' && $value == false) {
$this->updateManialink = false;
$ml = new ManiaLink(self::MLID_KARMA);
$mltext = $ml->render()->saveXML();
@ -680,21 +664,19 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$this->mxKarma['connectionInProgress'] = true;
$self = $this;
$this->maniaControl->fileReader->loadFile($query, function ($data, $error) use(&$self, $mxKarmaCode) {
$this->maniaControl->fileReader->loadFile($query, function ($data, $error) use (&$self, $mxKarmaCode) {
if (!$error) {
$data = json_decode($data);
if ($data->success) {
$self->mxKarma['session'] = $data->data;
$self->activateSession($mxKarmaCode);
}
else {
} else {
$self->maniaControl->log("Error while authenticating on Mania-Exchange Karma");
// TODO remove temp trigger
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message);
$self->mxKarma['connectionInProgress'] = false;
}
}
else {
} else {
$self->maniaControl->log($error);
// TODO remove temp trigger
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error);
@ -716,7 +698,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$query .= '&activationHash=' . urlencode($hash);
$self = $this;
$this->maniaControl->fileReader->loadFile($query, function ($data, $error) use(&$self, $query) {
$this->maniaControl->fileReader->loadFile($query, function ($data, $error) use (&$self, $query) {
if (!$error) {
$data = json_decode($data);
if ($data->success && $data->data->activated) {
@ -725,15 +707,13 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
// Fetch the Mx Karma Votes
$self->getMxKarmaVotes();
}
else {
} else {
$self->maniaControl->log("Error while authenticating on Mania-Exchange Karma " . $data->data->message);
// TODO remove temp trigger
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $data->data->message . " url Query " . $query);
$self->mxKarma['connectionInProgress'] = false;
}
}
else {
} else {
// TODO remove temp trigger
$self->maniaControl->errorHandler->triggerDebugNotice("Error while authenticating on Mania-Exchange Karma " . $error);
$self->maniaControl->log($error);
@ -765,8 +745,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
if ($gameMode == 'Script') {
$scriptName = $this->maniaControl->client->getScriptName();
$properties['gamemode'] = $scriptName["CurrentValue"];
}
else {
} else {
$properties['gamemode'] = $gameMode;
}
@ -776,22 +755,20 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
if (!$player) {
$properties['getvotesonly'] = false;
$properties['playerlogins'] = array();
foreach ($this->maniaControl->playerManager->getPlayers() as $plyr) {
foreach($this->maniaControl->playerManager->getPlayers() as $plyr) {
/**
*
* @var Player $player
*/
$properties['playerlogins'][] = $plyr->login;
}
}
else {
} else {
$properties['getvotesonly'] = true;
$properties['playerlogins'] = array($player->login);
}
$content = json_encode($properties);
$self = $this;
$this->maniaControl->fileReader->postData(self::MX_KARMA_URL . self::MX_KARMA_GETMAPRATING . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($data, $error) use(&$self, &$player) {
$this->maniaControl->fileReader->postData(self::MX_KARMA_URL . self::MX_KARMA_GETMAPRATING . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($data, $error) use (&$self, &$player) {
if (!$error) {
$data = json_decode($data);
if ($data->success) {
@ -804,21 +781,19 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$self->mxKarma["modeVoteAverage"] = $data->data->modevoteaverage;
}
foreach ($data->data->votes as $votes) {
foreach($data->data->votes as $votes) {
$self->mxKarma["votes"][$votes->login] = $votes->vote;
}
$self->updateManialink = true;
$self->maniaControl->callbackManager->triggerCallback($self::CB_KARMA_MXUPDATED, $self->mxKarma);
$self->maniaControl->log("MX-Karma Votes successfully fetched");
}
else {
} else {
$self->maniaControl->log("Error while fetching votes: " . $data->data->message);
// TODO remove temp trigger
$self->maniaControl->errorHandler->triggerDebugNotice("Error while fetching votes: " . $data->data->message . " " . KarmaPlugin::MX_KARMA_URL . KarmaPlugin::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($self->mxKarma['session']->sessionKey));
}
}
else {
} else {
$self->maniaControl->log($error);
}
}, $content, false, 'application/json');
@ -863,7 +838,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
}
$votes = array();
while ($row = $result2->fetch_object()) {
while($row = $result2->fetch_object()) {
array_push($votes, array("login" => $row->login, "nickname" => $row->nickname, "vote" => $row->vote * 100));
}
@ -930,15 +905,13 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
if ($gameMode == 'Script') {
$scriptName = $this->maniaControl->client->getScriptName();
$properties['gamemode'] = $scriptName["CurrentValue"];
}
else {
} else {
$properties['gamemode'] = $gameMode;
}
if ($import) {
$properties['maptime'] = 0;
}
else {
} else {
$properties['maptime'] = time() - $this->mxKarma['startTime'];
}
@ -952,19 +925,17 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$content = json_encode($properties);
$self = $this;
$this->maniaControl->fileReader->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($data, $error) use(&$self) {
$this->maniaControl->fileReader->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($data, $error) use (&$self) {
if (!$error) {
$data = json_decode($data);
if ($data->success) {
$self->maniaControl->log("Votes successfully permitted");
}
else {
} else {
$self->maniaControl->log("Error while updating votes: " . $data->data->message);
// TODO remove temp trigger
$self->maniaControl->errorHandler->triggerDebugNotice("Error while updating votes: " . $data->data->message . " " . KarmaPlugin::MX_KARMA_URL . $self::MX_KARMA_SAVEVOTES . "?sessionKey=" . urlencode($self->mxKarma['session']->sessionKey));
}
}
else {
} else {
$self->maniaControl->log($error);
}
}, $content, false, 'application/json');

View File

@ -12,6 +12,7 @@ use FML\Script\Features\Paging;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener;
use ManiaControl\Settings\SettingManager;
@ -96,7 +97,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
// Register for callbacks
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);
$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(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$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 ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Maps\MapManager;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\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_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
$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_REMOVEFROMQUEUE, $this, 'handleManiaLinkAnswerRemove');
@ -86,7 +86,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$this->maniaControl->settingManager->initSetting($this, self::QUEUE_CHATMESSAGES, true);
foreach($this->maniaControl->playerManager->getPlayers() as $player) {
if($player->isSpectator) {
if ($player->isSpectator) {
$this->spectators[$player->login] = $player->login;
$this->maniaControl->client->forceSpectator($player->login, 1);
$this->showJoinQueueWidget($player);
@ -171,12 +171,12 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$maxPlayers = $this->maniaControl->client->getMaxPlayers();
$this->maxPlayers = $maxPlayers['CurrentValue'];
if($player->isSpectator) {
if ($player->isSpectator) {
$this->spectators[$player->login] = $player->login;
$this->maniaControl->client->forceSpectator($player->login, 1);
$this->showJoinQueueWidget($player);
} else {
if(count($this->queue) != 0) {
if (count($this->queue) != 0) {
$this->maniaControl->client->forceSpectator($player->login, 1);
$this->spectators[$player->login] = $player->login;
$this->showJoinQueueWidget($player);
@ -193,7 +193,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$maxPlayers = $this->maniaControl->client->getMaxPlayers();
$this->maxPlayers = $maxPlayers['CurrentValue'];
if(isset($this->spectators[$player->login])) {
if (isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]);
}
$this->removePlayerFromQueue($player->login);
@ -209,27 +209,27 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$login = $callback[1][0]['Login'];
$player = $this->maniaControl->playerManager->getPlayer($login);
if(!is_null($player)) {
if($player->isSpectator) {
if(!isset($this->spectators[$player->login])) {
if (!is_null($player)) {
if ($player->isSpectator) {
if (!isset($this->spectators[$player->login])) {
$this->maniaControl->client->forceSpectator($player->login, 1);
$this->spectators[$player->login] = $player->login;
$this->showJoinQueueWidget($player);
}
} else {
$this->removePlayerFromQueue($player->login);
if(isset($this->spectators[$player->login])) {
if (isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]);
}
$found = false;
foreach($this->showPlay as $showPlay) {
if($showPlay['player']->login == $player->login) {
if ($showPlay['player']->login == $player->login) {
$found = true;
}
}
if(!$found) {
if (!$found) {
$this->hideQueueWidget($player);
}
}
@ -240,7 +240,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* Function called on every second.
*/
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();
}
@ -250,7 +250,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
}
foreach($this->showPlay as $showPlay) {
if(($showPlay['time'] + 5) < time()) {
if (($showPlay['time'] + 5) < time()) {
$this->hideQueueWidget($showPlay['player']);
unset($this->showPlay[$showPlay['player']->login]);
}
@ -293,7 +293,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* Function used to move the first queued player to the
*/
private function moveFirstPlayerToPlay() {
if(count($this->queue) > 0) {
if (count($this->queue) > 0) {
$firstPlayer = $this->maniaControl->playerManager->getPlayer($this->queue[0]->login);
$this->forcePlayerToPlay($firstPlayer);
}
@ -305,9 +305,11 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* @param 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 {
$this->maniaControl->client->forceSpectator($player->login, 2);
} catch(Exception $e) {
@ -325,7 +327,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$teams = array();
/** @var Player $playerObj */
foreach($this->maniaControl->playerManager->players as $playerObj) {
if(!isset($teams[$playerObj->teamId])) {
if (!isset($teams[$playerObj->teamId])) {
$teams[$playerObj->teamId] = 1;
} else {
$teams[$playerObj->teamId]++;
@ -335,21 +337,21 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$smallestTeam = null;
$smallestSize = 999;
foreach($teams as $team => $size) {
if($size < $smallestSize) {
if ($size < $smallestSize) {
$smallestTeam = $team;
$smallestSize = $size;
}
}
try {
if($smallestTeam != -1) {
if ($smallestTeam != -1) {
$this->maniaControl->client->forcePlayerTeam($player->login, $smallestTeam);
}
} catch(Exception $e) {
// 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]);
}
$this->removePlayerFromQueue($player->login);
@ -366,16 +368,18 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* @return bool
*/
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) {
if($queuedPlayer->login == $player->login) {
if ($queuedPlayer->login == $player->login) {
$this->maniaControl->chat->sendError('You\'re already in the queue!', $player->login);
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->sendChatMessage('$<$fff' . $player->nickname . '$> just joined the queue!');
}
@ -392,7 +396,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$count = 0;
$newQueue = array();
foreach($this->queue as $queuePlayer) {
if($queuePlayer->login != $login) {
if ($queuePlayer->login != $login) {
$newQueue[$count] = $queuePlayer;
$count++;
}
@ -407,8 +411,8 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
* @param $message
*/
private function sendChatMessage($message) {
if($this->maniaControl->settingManager->getSetting($this, self::QUEUE_CHATMESSAGES)) {
$this->maniaControl->chat->sendChat('$z$s$090[Queue] '.$message);
if ($this->maniaControl->settingManager->getSetting($this, self::QUEUE_CHATMESSAGES)) {
$this->maniaControl->chat->sendChat('$z$s$090[Queue] ' . $message);
}
}
@ -465,17 +469,17 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$inQueue = false;
foreach($this->queue as $queuedPlayer) {
if($queuedPlayer->login == $player->login) {
if ($queuedPlayer->login == $player->login) {
$inQueue = true;
}
}
if($inQueue) {
if ($inQueue) {
$message = '$fff$sYou\'re in the queue (click to unqueue).';
$position = 0;
foreach(array_values($this->queue) as $i => $queuePlayer) {
if($player->login == $queuePlayer->login) {
if ($player->login == $queuePlayer->login) {
$position = ($i + 1);
}
}
@ -486,7 +490,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$statusLabel->setAction(self::ML_REMOVEFROMQUEUE);
$cameraQuad->setAction(self::ML_REMOVEFROMQUEUE);
} else {
if(count($this->queue) < $max_queue) {
if (count($this->queue) < $max_queue) {
$message = '$0ff$sClick to join spectator waiting list.';
$messageLabel->setAction(self::ML_ADDTOQUEUE);
$backgroundQuad->setAction(self::ML_ADDTOQUEUE);

View File

@ -1,6 +1,7 @@
<?php
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Maps\Map;
@ -92,7 +93,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
//Register CallbackListeners
$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
$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\Script\Script;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Formatter;
use ManiaControl\ManiaControl;
@ -101,8 +102,8 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
$this->maniaControl->manialinkManager->customUIManager->setChallengeInfoVisible(false);
// Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleOnBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_ENDMAP, $this, 'handleOnEndMap');
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'handleOnBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ENDMAP, $this, 'handleOnEndMap');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');