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_Button;
use FML\Controls\Labels\Label_Text; use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad; use FML\Controls\Quad;
use FML\Controls\Quads\Quad_Icons64x64_1; 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\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
@ -157,9 +157,12 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
} }
public function handlePlayerDisconnect(array $callback) { public function handlePlayerDisconnect(array $callback) {
$login = $callback[1]->login; /** @var Player $player */
if(isset($this->spectators[$login])) unset($this->spectators[$login]); $player = $callback[1];
$this->removePlayerFromQueue($login); if(isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]);
}
$this->removePlayerFromQueue($player->login);
$this->moveFirstPlayerToPlay(); $this->moveFirstPlayerToPlay();
} }
@ -189,7 +192,7 @@ 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]);
} }
@ -201,9 +204,9 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
} }
public function handleManiaLinkAnswerRemove(array $chatCallback, Player $player) { public function handleManiaLinkAnswerRemove(array $chatCallback, Player $player) {
$this->removePlayerFromQueue($player); $this->removePlayerFromQueue($player->login);
$this->showJoinQueueWidget($player); $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() { private function moveFirstPlayerToPlay() {
@ -217,17 +220,19 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
if($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > count($this->maniaControl->playerManager->players)) { if($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > count($this->maniaControl->playerManager->players)) {
$this->maniaControl->client->forceSpectator($player->login, 2); $this->maniaControl->client->forceSpectator($player->login, 2);
$this->maniaControl->client->forceSpectator($player->login, 0); $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->removePlayerFromQueue($player->login);
$this->showPlayWidget($player); $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) { private function addPlayerToQueue(Player $player) {
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->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).'; $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);
} }
} }
$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); $messageLabel->setAction(self::ML_REMOVEFROMQUEUE);
$backgroundQuad->setAction(self::ML_REMOVEFROMQUEUE); $backgroundQuad->setAction(self::ML_REMOVEFROMQUEUE);
$statusLabel->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!'; $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); $messageLabel->setText($message);