queue fixes

This commit is contained in:
kremsy 2014-01-24 21:40:12 +01:00 committed by Steffen Schröder
parent d9ba67947a
commit 1d8c9e60e3

View File

@ -3,9 +3,9 @@ use FML\Controls\Frame;
use FML\Controls\Labels\Label_Button;
use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Commands\CommandListener;
@ -157,9 +157,12 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
}
public function handlePlayerDisconnect(array $callback) {
$login = $callback[1]->login;
if(isset($this->spectators[$login])) unset($this->spectators[$login]);
$this->removePlayerFromQueue($login);
/** @var Player $player */
$player = $callback[1];
if(isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]);
}
$this->removePlayerFromQueue($player->login);
$this->moveFirstPlayerToPlay();
}
@ -189,7 +192,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]);
}
@ -201,9 +204,9 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
}
public function handleManiaLinkAnswerRemove(array $chatCallback, Player $player) {
$this->removePlayerFromQueue($player);
$this->removePlayerFromQueue($player->login);
$this->showJoinQueueWidget($player);
$this->maniaControl->chat->sendChat('$z$s$090[Queue] $<$fff'.$player->nickname.'$> has left the queue!');
$this->maniaControl->chat->sendChat('$z$s$090[Queue] $<$fff' . $player->nickname . '$> has left the queue!');
}
private function moveFirstPlayerToPlay() {
@ -217,17 +220,19 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
if($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > count($this->maniaControl->playerManager->players)) {
$this->maniaControl->client->forceSpectator($player->login, 2);
$this->maniaControl->client->forceSpectator($player->login, 0);
if(isset($this->spectators[$player->login])) unset($this->spectators[$player->login]);
if(isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]);
}
$this->removePlayerFromQueue($player->login);
$this->showPlayWidget($player);
$this->maniaControl->chat->sendChat('$z$s$090[Queue] $<$fff'.$player->nickname.'$> has a free spot and is now playing!');
$this->maniaControl->chat->sendChat('$z$s$090[Queue] $<$fff' . $player->nickname . '$> has a free spot and is now playing!');
}
}
private function addPlayerToQueue(Player $player) {
if($this->maniaControl->settingManager->getSetting($this, self::QUEUE_MAX) > count($this->queue)) {
$this->queue[count($this->queue)] = $player;
$this->maniaControl->chat->sendChat('$z$s$090[Queue] $<$fff'.$player->nickname.'$> just joined the queue!');
$this->maniaControl->chat->sendChat('$z$s$090[Queue] $<$fff' . $player->nickname . '$> just joined the queue!');
}
}
@ -296,13 +301,13 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$message = '$fff$sYou\'re in the queue (click to unqueue).';
$position = 0;
foreach (array_values($this->queue) as $i => $queuePlayer) {
foreach(array_values($this->queue) as $i => $queuePlayer) {
if($player->login == $queuePlayer->login) {
$position = ($i+1);
$position = ($i + 1);
}
}
$statusLabel->setText('$aaaStatus: In queue, ('.$position.'/'.count($this->queue).') Waiting: '.count($this->queue).'/'.$max_queue.'');
$statusLabel->setText('$aaaStatus: In queue, (' . $position . '/' . count($this->queue) . ') Waiting: ' . count($this->queue) . '/' . $max_queue . '');
$messageLabel->setAction(self::ML_REMOVEFROMQUEUE);
$backgroundQuad->setAction(self::ML_REMOVEFROMQUEUE);
$statusLabel->setAction(self::ML_REMOVEFROMQUEUE);
@ -318,7 +323,7 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
$message = '$f00The waiting list is full!';
}
$statusLabel->setText('$aaaStatus: Not queued spectator Waiting: '.count($this->queue).'/'.$max_queue.'');
$statusLabel->setText('$aaaStatus: Not queued spectator Waiting: ' . count($this->queue) . '/' . $max_queue . '');
}
$messageLabel->setText($message);