From 74d963cca54464e1e56d45760b1e46a572fe5939 Mon Sep 17 00:00:00 2001 From: Max Klaversma Date: Sun, 27 Apr 2014 00:55:39 +0200 Subject: [PATCH] Added replay votes + admin replay --- application/core/Maps/MapCommands.php | 20 ++++++++++++++++++++ application/core/Maps/MapQueue.php | 10 ++++++++++ application/plugins/CustomVotes.php | 5 +++++ 3 files changed, 35 insertions(+) diff --git a/application/core/Maps/MapCommands.php b/application/core/Maps/MapCommands.php index 82f7135a..4f71ca98 100644 --- a/application/core/Maps/MapCommands.php +++ b/application/core/Maps/MapCommands.php @@ -46,6 +46,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb // Register for admin chat commands $this->maniaControl->commandManager->registerCommandListener(array('nextmap', 'next', 'skip'), $this, 'command_NextMap', true); $this->maniaControl->commandManager->registerCommandListener(array('restartmap', 'resmap', 'res'), $this, 'command_RestartMap', true); + $this->maniaControl->commandManager->registerCommandListener(array('replaymap', 'replay'), $this, 'command_ReplayMap', true); $this->maniaControl->commandManager->registerCommandListener(array('addmap', 'add'), $this, 'command_AddMap', true); $this->maniaControl->commandManager->registerCommandListener(array('removemap', 'removethis', 'erasemap', 'erasethis'), $this, 'command_RemoveMap', true); $this->maniaControl->commandManager->registerCommandListener(array('shufflemaps', 'shuffle'), $this, 'command_ShuffleMaps', true); @@ -215,6 +216,25 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb } } + ////$this->maniaControl->mapManager->mapQueue->addFirstMapToMapQueue($this->currentVote->voter, $this->maniaControl->mapManager->getCurrentMap()); + /** + * Handle replaymap command + * + * @param array $chat + * @param \ManiaControl\Players\Player $player + */ + public function command_ReplayMap(array $chat, Player $player) { + if (!$this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_RESTART_MAP)) { + $this->maniaControl->authenticationManager->sendNotAllowed($player); + return; + } + $message = '$<' . $player->nickname . '$> replays the current Map!'; + $this->maniaControl->chat->sendSuccess($message); + $this->maniaControl->log($message, true); + + $this->maniaControl->mapManager->mapQueue->addFirstMapToMapQueue($player, $this->maniaControl->mapManager->getCurrentMap()); + } + /** * Handle /maps command * diff --git a/application/core/Maps/MapQueue.php b/application/core/Maps/MapQueue.php index 716136e0..4162f0c9 100644 --- a/application/core/Maps/MapQueue.php +++ b/application/core/Maps/MapQueue.php @@ -91,6 +91,16 @@ class MapQueue implements CallbackListener, CommandListener { $this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('clear')); } + public function addFirstMapToMapQueue($player, $map) { + if ($map) { + if (array_key_exists($map->uid, $this->queuedMaps)) { + unset($this->queuedMaps[$map->uid]); + } + + array_unshift($this->queuedMaps, array($player, $map)); + } + } + /** * Adds a Map to the map-queue diff --git a/application/plugins/CustomVotes.php b/application/plugins/CustomVotes.php index aaa14b38..8795af96 100644 --- a/application/plugins/CustomVotes.php +++ b/application/plugins/CustomVotes.php @@ -136,6 +136,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP $this->defineVote("restartmap", "Vote for Restart Map"); $this->defineVote("restart", "Vote for Restart Map"); $this->defineVote("pausegame", "Vote for Pause Game"); + $this->defineVote("replay", "Vote to replay current map"); foreach($this->voteCommands as $name => $voteCommand) { $this->maniaControl->commandManager->registerCommandListener($name, $this, 'handleChatVote'); @@ -330,6 +331,10 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP $this->maniaControl->client->sendModeScriptCommands(array('Command_ForceWarmUp' => True)); $this->maniaControl->chat->sendInformation('$s$f8fVote to $fffpause the current game$f8f has been successfull!'); break; + case 'replay': + $this->maniaControl->mapManager->mapQueue->addFirstMapToMapQueue($this->currentVote->voter, $this->maniaControl->mapManager->getCurrentMap()); + $this->maniaControl->chat->sendInformation('$s$f8fVote to $fffreplay the map$f8f has been successfull!'); + break; } } else { $this->maniaControl->chat->sendError('Vote Failed!');