code refactoring
- improved comparing & checking - improved string composition
This commit is contained in:
@ -80,21 +80,20 @@ class Map {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get's the gameType of the Current Map
|
||||
* Get the Game Type of the Map
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getGame() {
|
||||
switch ($this->environment) {
|
||||
case 'Storm':
|
||||
return "sm";
|
||||
return 'sm';
|
||||
case 'Canyon':
|
||||
case 'Stadium':
|
||||
case 'Valley':
|
||||
return "tm";
|
||||
default:
|
||||
return "";
|
||||
return 'tm';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +103,7 @@ class Map {
|
||||
*/
|
||||
public function updateAvailable() {
|
||||
|
||||
if ($this->mx && ($this->lastUpdate < strtotime($this->mx->updated) || $this->uid != $this->mx->uid)) {
|
||||
if ($this->mx && ($this->lastUpdate < strtotime($this->mx->updated) || $this->uid !== $this->mx->uid)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -342,11 +342,11 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
||||
/** @var Map $map */
|
||||
foreach ($maps as $map) {
|
||||
if ($map->authorLogin == $author) {
|
||||
$mapList[] = $map;
|
||||
array_push($mapList, $map);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($mapList) == 0) {
|
||||
if (empty($mapList)) {
|
||||
$this->maniaControl->chat->sendError('There are no maps to show!', $player->login);
|
||||
return;
|
||||
}
|
||||
@ -363,23 +363,32 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
||||
public function command_List(array $chatCallback, Player $player) {
|
||||
$chatCommands = explode(' ', $chatCallback[1][2]);
|
||||
$this->maniaControl->mapManager->mapList->playerCloseWidget($player);
|
||||
|
||||
if (isset($chatCommands[1])) {
|
||||
if ($chatCommands[1] == ' ' || $chatCommands[1] == 'all') {
|
||||
$this->maniaControl->mapManager->mapList->showMapList($player);
|
||||
} elseif ($chatCommands[1] == 'best') {
|
||||
$this->showMapListKarma(true, $player);
|
||||
} elseif ($chatCommands[1] == 'worst') {
|
||||
$this->showMapListKarma(false, $player);
|
||||
} elseif ($chatCommands[1] == 'newest') {
|
||||
$this->showMapListDate(true, $player);
|
||||
} elseif ($chatCommands[1] == 'oldest') {
|
||||
$this->showMapListDate(false, $player);
|
||||
} elseif ($chatCommands[1] == 'author') {
|
||||
if (isset($chatCommands[2])) {
|
||||
$this->showMaplistAuthor($chatCommands[2], $player);
|
||||
} else {
|
||||
$this->maniaControl->chat->sendError('There are no maps to show!', $player->login);
|
||||
}
|
||||
$listParam = strtolower($chatCommands[1]);
|
||||
switch ($listParam) {
|
||||
case 'best':
|
||||
$this->showMapListKarma(true, $player);
|
||||
break;
|
||||
case 'worst':
|
||||
$this->showMapListKarma(false, $player);
|
||||
break;
|
||||
case 'newest':
|
||||
$this->showMapListDate(true, $player);
|
||||
break;
|
||||
case 'oldest':
|
||||
$this->showMapListDate(false, $player);
|
||||
break;
|
||||
case 'author':
|
||||
if (isset($chatCommands[2])) {
|
||||
$this->showMaplistAuthor($chatCommands[2], $player);
|
||||
} else {
|
||||
$this->maniaControl->chat->sendError('Missing Author Login!', $player->login);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$this->maniaControl->mapManager->mapList->showMapList($player);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$this->maniaControl->mapManager->mapList->showMapList($player);
|
||||
@ -409,7 +418,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
||||
$plus = 0;
|
||||
foreach ($votes as $vote) {
|
||||
if (isset($vote->vote)) {
|
||||
if ($vote->vote != 0.5) {
|
||||
if ($vote->vote !== 0.5) {
|
||||
if ($vote->vote < 0.5) {
|
||||
$min = $min + $vote->count;
|
||||
} else {
|
||||
|
@ -240,7 +240,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$mapFrame->setZ(0.1);
|
||||
$mapFrame->setY($y);
|
||||
|
||||
if ($id % 2 != 0) {
|
||||
if ($id % 2 !== 0) {
|
||||
$lineQuad = new Quad_BgsPlayerCard();
|
||||
$mapFrame->add($lineQuad);
|
||||
$lineQuad->setSize($width, 4);
|
||||
@ -422,7 +422,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$plus = 0;
|
||||
foreach ($votes as $vote) {
|
||||
if (isset($vote->vote)) {
|
||||
if ($vote->vote != 0.5) {
|
||||
if ($vote->vote !== 0.5) {
|
||||
if ($vote->vote < 0.5) {
|
||||
$min = $min + $vote->count;
|
||||
} else {
|
||||
|
@ -310,7 +310,7 @@ class MapManager implements CallbackListener {
|
||||
try {
|
||||
$this->maniaControl->client->writeFile($relativeMapFileName, $file);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
if ($e->getMessage() == 'data are too big') {
|
||||
if ($e->getMessage() === 'data are too big') {
|
||||
$this->maniaControl->chat->sendError("Map is too big for a remote save.", $login);
|
||||
return;
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (count($this->queuedMaps) == 0) {
|
||||
if (empty($this->queuedMaps)) {
|
||||
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $admin->login);
|
||||
return;
|
||||
}
|
||||
@ -135,12 +135,20 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
$chatCommands = explode(' ', $chatCallback[1][2]);
|
||||
|
||||
if (isset($chatCommands[1])) {
|
||||
if ($chatCommands[1] == ' ' || $chatCommands[1] == 'list') {
|
||||
$this->showMapQueue($player);
|
||||
} elseif ($chatCommands[1] == 'display') {
|
||||
$this->showMapQueueManialink($player);
|
||||
} elseif ($chatCommands[1] == 'clear') {
|
||||
$this->clearMapQueue($player);
|
||||
$listParam = strtolower($chatCommands[1]);
|
||||
switch ($listParam) {
|
||||
case 'list':
|
||||
$this->showMapQueue($player);
|
||||
break;
|
||||
case 'display':
|
||||
$this->showMapQueueManialink($player);
|
||||
break;
|
||||
case 'clear':
|
||||
$this->clearMapQueue($player);
|
||||
break;
|
||||
default:
|
||||
$this->showMapQueue($player);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$this->showMapQueue($player);
|
||||
@ -153,7 +161,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
* @param Player $player
|
||||
*/
|
||||
public function showMapQueue(Player $player) {
|
||||
if (count($this->queuedMaps) == 0) {
|
||||
if (empty($this->queuedMaps)) {
|
||||
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
|
||||
return;
|
||||
}
|
||||
@ -174,14 +182,14 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
* @param Player $player
|
||||
*/
|
||||
public function showMapQueueManialink(Player $player) {
|
||||
if (count($this->queuedMaps) == 0) {
|
||||
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
|
||||
if (empty($this->queuedMaps)) {
|
||||
$this->maniaControl->chat->sendError('There are no Maps in the Jukebox!', $player);
|
||||
return;
|
||||
}
|
||||
|
||||
$maps = array();
|
||||
foreach ($this->queuedMaps as $queuedMap) {
|
||||
$maps[] = $queuedMap[1];
|
||||
array_push($maps, $queuedMap[1]);
|
||||
}
|
||||
|
||||
$this->maniaControl->mapManager->mapList->showMapList($player, $maps);
|
||||
@ -220,12 +228,12 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
*/
|
||||
public function addMapToMapQueue($login, $uid) {
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
if (!$player) {
|
||||
return;
|
||||
}
|
||||
|
||||
//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)) {
|
||||
$admin = true;
|
||||
}
|
||||
$isModerator = $this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||
|
||||
$mapsForPlayer = 0;
|
||||
foreach ($this->queuedMaps as $queuedMap) {
|
||||
@ -234,16 +242,15 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
}
|
||||
}
|
||||
|
||||
$maxPlayer = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_MAPLIMIT_PLAYER);
|
||||
$maxAdmin = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_MAPLIMIT_ADMIN);
|
||||
|
||||
if ($admin && $maxAdmin != -1) {
|
||||
if ($mapsForPlayer == $maxAdmin) {
|
||||
if ($isModerator) {
|
||||
$maxAdmin = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_MAPLIMIT_ADMIN);
|
||||
if ($maxAdmin >= 0 && $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) {
|
||||
} else {
|
||||
$maxPlayer = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_MAPLIMIT_PLAYER);
|
||||
if ($maxPlayer >= 0 && $mapsForPlayer >= $maxPlayer) {
|
||||
$this->maniaControl->chat->sendError('You already have $<$fff' . $maxPlayer . '$> map(s) in the Map-Queue!', $login);
|
||||
return;
|
||||
}
|
||||
@ -308,9 +315,8 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
}
|
||||
|
||||
$this->nextMap = null;
|
||||
if ($this->maniaControl->settingManager->getSettingValue($this, self::SETTING_SKIP_MAP_ON_LEAVE) == true) {
|
||||
|
||||
//Skip Map if requester has left
|
||||
if ($this->maniaControl->settingManager->getSettingValue($this, self::SETTING_SKIP_MAP_ON_LEAVE)) {
|
||||
// Skip Map if requester has left
|
||||
foreach ($this->queuedMaps as $queuedMap) {
|
||||
$player = $queuedMap[0];
|
||||
|
||||
@ -324,7 +330,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
break;
|
||||
}
|
||||
|
||||
if ($this->maniaControl->settingManager->getSettingValue($this, self::SETTING_SKIP_MAPQUEUE_ADMIN) == false) {
|
||||
if (!$this->maniaControl->settingManager->getSettingValue($this, self::SETTING_SKIP_MAPQUEUE_ADMIN)) {
|
||||
//Check if the queuer is a admin
|
||||
if ($player->authLevel > 0) {
|
||||
break;
|
||||
|
Reference in New Issue
Block a user