applied common formatting
This commit is contained in:
@ -14,9 +14,9 @@ use ManiaControl\Players\Player;
|
||||
/**
|
||||
* MapQueue Class
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class MapQueue implements CallbackListener, CommandListener {
|
||||
/*
|
||||
@ -34,7 +34,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
|
||||
const ADMIN_COMMAND_CLEAR_MAPQUEUE = 'clearmapqueue';
|
||||
const ADMIN_COMMAND_CLEAR_JUKEBOX = 'clearjukebox';
|
||||
|
||||
|
||||
/*
|
||||
* Private Properties
|
||||
*/
|
||||
@ -75,7 +75,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
* Adds current map to buffer on startup
|
||||
*/
|
||||
public function handleAfterInit() {
|
||||
$currentMap = $this->maniaControl->mapManager->getCurrentMap();
|
||||
$currentMap = $this->maniaControl->mapManager->getCurrentMap();
|
||||
$this->buffer[] = $currentMap->uid;
|
||||
}
|
||||
|
||||
@ -90,6 +90,34 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
$this->clearMapQueue($admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the Map Queue
|
||||
*
|
||||
* @param $admin
|
||||
*/
|
||||
public function clearMapQueue($admin) {
|
||||
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
|
||||
return;
|
||||
}
|
||||
|
||||
if (count($this->queuedMaps) == 0) {
|
||||
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $admin->login);
|
||||
return;
|
||||
}
|
||||
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
|
||||
//Destroy map - queue list
|
||||
$this->queuedMaps = array();
|
||||
|
||||
$this->maniaControl->chat->sendInformation('$fa0' . $title . ' $<$fff' . $admin->nickname . '$> cleared the Queued-Map list!');
|
||||
$this->maniaControl->log($title . ' ' . Formatter::stripCodes($admin->nickname) . ' cleared the Queued-Map list!');
|
||||
|
||||
// Trigger callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('clear'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the mapqueue/jukebox command
|
||||
*
|
||||
@ -99,12 +127,12 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
public function command_MapQueue(array $chat, Player $player) {
|
||||
$chatCommands = explode(' ', $chat[1][2]);
|
||||
|
||||
if(isset($chatCommands[1])) {
|
||||
if($chatCommands[1] == ' ' || $chatCommands[1] == 'list') {
|
||||
if (isset($chatCommands[1])) {
|
||||
if ($chatCommands[1] == ' ' || $chatCommands[1] == 'list') {
|
||||
$this->showMapQueue($player);
|
||||
} elseif($chatCommands[1] == 'display') {
|
||||
} elseif ($chatCommands[1] == 'display') {
|
||||
$this->showMapQueueManialink($player);
|
||||
} elseif($chatCommands[1] == 'clear') {
|
||||
} elseif ($chatCommands[1] == 'clear') {
|
||||
$this->clearMapQueue($player);
|
||||
}
|
||||
} else {
|
||||
@ -118,15 +146,15 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
* @param $player
|
||||
*/
|
||||
public function showMapQueue($player) {
|
||||
if(count($this->queuedMaps) == 0) {
|
||||
if (count($this->queuedMaps) == 0) {
|
||||
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
|
||||
return;
|
||||
}
|
||||
|
||||
$message = '$fa0Upcoming maps in the Map-Queue:';
|
||||
$i = 1;
|
||||
foreach($this->queuedMaps as $queuedMap) {
|
||||
$message .= ' $<$fff'.$i.'$>. [$<$fff'.Formatter::stripCodes($queuedMap[1]->name).'$>]';
|
||||
$i = 1;
|
||||
foreach ($this->queuedMaps as $queuedMap) {
|
||||
$message .= ' $<$fff' . $i . '$>. [$<$fff' . Formatter::stripCodes($queuedMap[1]->name) . '$>]';
|
||||
$i++;
|
||||
}
|
||||
|
||||
@ -139,13 +167,13 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
* @param $player
|
||||
*/
|
||||
public function showMapQueueManialink($player) {
|
||||
if(count($this->queuedMaps) == 0) {
|
||||
if (count($this->queuedMaps) == 0) {
|
||||
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
|
||||
return;
|
||||
}
|
||||
|
||||
$maps = array();
|
||||
foreach($this->queuedMaps as $queuedMap) {
|
||||
foreach ($this->queuedMaps as $queuedMap) {
|
||||
$maps[] = $queuedMap[1];
|
||||
}
|
||||
|
||||
@ -161,34 +189,6 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
return $this->buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the Map Queue
|
||||
*
|
||||
* @param $admin
|
||||
*/
|
||||
public function clearMapQueue($admin) {
|
||||
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
|
||||
return;
|
||||
}
|
||||
|
||||
if(count($this->queuedMaps) == 0) {
|
||||
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $admin->login);
|
||||
return;
|
||||
}
|
||||
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
|
||||
//Destroy map - queue list
|
||||
$this->queuedMaps = array();
|
||||
|
||||
$this->maniaControl->chat->sendInformation('$fa0'. $title . ' $<$fff' . $admin->nickname . '$> cleared the Queued-Map list!');
|
||||
$this->maniaControl->log($title . ' ' . Formatter::stripCodes($admin->nickname) . ' cleared the Queued-Map list!');
|
||||
|
||||
// Trigger callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('clear'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds map as first map in queue (for /replay)
|
||||
*
|
||||
@ -216,15 +216,13 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
|
||||
//Check if player is allowed to add (another) map
|
||||
$admin = false;
|
||||
if($this->maniaControl->authenticationManager->checkRight($player, 2) ||
|
||||
$this->maniaControl->authenticationManager->checkRight($player, 3) ||
|
||||
$this->maniaControl->authenticationManager->checkRight($player, 4)) {
|
||||
if ($this->maniaControl->authenticationManager->checkRight($player, 2) || $this->maniaControl->authenticationManager->checkRight($player, 3) || $this->maniaControl->authenticationManager->checkRight($player, 4)) {
|
||||
$admin = true;
|
||||
}
|
||||
|
||||
$mapsForPlayer = 0;
|
||||
foreach($this->queuedMaps as $queuedMap) {
|
||||
if($queuedMap[0]->login == $login) {
|
||||
foreach ($this->queuedMaps as $queuedMap) {
|
||||
if ($queuedMap[0]->login == $login) {
|
||||
$mapsForPlayer++;
|
||||
}
|
||||
}
|
||||
@ -232,14 +230,14 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
$maxPlayer = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAPLIMIT_PLAYER);
|
||||
$maxAdmin = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAPLIMIT_ADMIN);
|
||||
|
||||
if($admin && $maxAdmin != -1) {
|
||||
if($mapsForPlayer == $maxAdmin) {
|
||||
$this->maniaControl->chat->sendError('You already have $<$fff'.$maxAdmin.'$> map(s) in the Map-Queue!', $login);
|
||||
if ($admin && $maxAdmin != -1) {
|
||||
if ($mapsForPlayer == $maxAdmin) {
|
||||
$this->maniaControl->chat->sendError('You already have $<$fff' . $maxAdmin . '$> map(s) in the Map-Queue!', $login);
|
||||
return;
|
||||
}
|
||||
} elseif(!$admin && $maxPlayer != -1) {
|
||||
if($mapsForPlayer == $maxPlayer) {
|
||||
$this->maniaControl->chat->sendError('You already have $<$fff'.$maxPlayer.'$> map(s) in the Map-Queue!', $login);
|
||||
} elseif (!$admin && $maxPlayer != -1) {
|
||||
if ($mapsForPlayer == $maxPlayer) {
|
||||
$this->maniaControl->chat->sendError('You already have $<$fff' . $maxPlayer . '$> map(s) in the Map-Queue!', $login);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -252,7 +250,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
|
||||
//TODO recently maps not able to add to queue-amps setting, and management
|
||||
// Check if map is in the buffer
|
||||
if(in_array($uid, $this->buffer)) {
|
||||
if (in_array($uid, $this->buffer)) {
|
||||
$this->maniaControl->chat->sendError('That map has recently been played!', $login);
|
||||
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
|
||||
return;
|
||||
@ -297,10 +295,10 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
*/
|
||||
public function endMap(Map $map) {
|
||||
$this->nextMap = null;
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE) == TRUE) {
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE) == true) {
|
||||
|
||||
//Skip Map if requester has left
|
||||
foreach($this->queuedMaps as $queuedMap) {
|
||||
foreach ($this->queuedMaps as $queuedMap) {
|
||||
$player = $queuedMap[0];
|
||||
|
||||
//found player, so play this map
|
||||
@ -308,7 +306,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
break;
|
||||
}
|
||||
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN) == FALSE) {
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN) == false) {
|
||||
//Check if the queuer is a admin
|
||||
if ($player->authLevel > 0) {
|
||||
break;
|
||||
@ -321,7 +319,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
//Player not found, so remove the map from the mapqueue
|
||||
array_shift($this->queuedMaps);
|
||||
|
||||
$this->maniaControl->chat->sendInformation('$fa0$<$fff' . $queuedMap[0]->name .'$> is skipped because $<' . $player->nickname . '$> left the game!');
|
||||
$this->maniaControl->chat->sendInformation('$fa0$<$fff' . $queuedMap[0]->name . '$> is skipped because $<' . $player->nickname . '$> left the game!');
|
||||
}
|
||||
}
|
||||
|
||||
@ -332,7 +330,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
return;
|
||||
}
|
||||
$map = $this->nextMap[1];
|
||||
$this->maniaControl->chat->sendInformation('$fa0Next map will be $<$fff' . $map->name .'$> as requested by $<' . $this->nextMap[0]->nickname . '$>.');
|
||||
$this->maniaControl->chat->sendInformation('$fa0Next map will be $<$fff' . $map->name . '$> as requested by $<' . $this->nextMap[0]->nickname . '$>.');
|
||||
|
||||
$this->maniaControl->client->chooseNextMap($map->fileName);
|
||||
}
|
||||
@ -343,11 +341,11 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
* @param Map $map
|
||||
*/
|
||||
public function beginMap(Map $map) {
|
||||
if(in_array($map->uid, $this->buffer)) {
|
||||
if (in_array($map->uid, $this->buffer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(count($this->buffer) >= $this->maniaControl->settingManager->getSetting($this, self::SETTING_BUFFERSIZE)) {
|
||||
if (count($this->buffer) >= $this->maniaControl->settingManager->getSetting($this, self::SETTING_BUFFERSIZE)) {
|
||||
array_shift($this->buffer);
|
||||
}
|
||||
|
||||
@ -370,7 +368,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
* @return array(Player $player, Map $map)
|
||||
*/
|
||||
public function getNextQueuedMap() {
|
||||
foreach($this->queuedMaps as $queuedMap) {
|
||||
foreach ($this->queuedMaps as $queuedMap) {
|
||||
//return the first Queued Map
|
||||
return $queuedMap;
|
||||
}
|
||||
@ -385,7 +383,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
public function getQueuedMapsRanking() {
|
||||
$i = 1;
|
||||
$queuedMaps = array();
|
||||
foreach($this->queuedMaps as $queuedMap) {
|
||||
foreach ($this->queuedMaps as $queuedMap) {
|
||||
$map = $queuedMap[1];
|
||||
$queuedMaps[$map->uid] = $i;
|
||||
$i++;
|
||||
@ -407,7 +405,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
* Dummy Function for testing
|
||||
*/
|
||||
public function printAllMaps() {
|
||||
foreach($this->queuedMaps as $map) {
|
||||
foreach ($this->queuedMaps as $map) {
|
||||
$map = $map[1];
|
||||
var_dump($map->name);
|
||||
}
|
||||
|
Reference in New Issue
Block a user