performed code formatting

This commit is contained in:
Steffen Schröder
2014-08-05 02:17:41 +02:00
parent 98b5f132dc
commit 28d2c08936
66 changed files with 4054 additions and 1901 deletions

View File

@ -56,25 +56,38 @@ class MapQueue implements CallbackListener, CommandListener {
$this->maniaControl = $maniaControl;
// Callbacks
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ENDMAP, $this, 'endMap');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'beginMap');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::ENDMAP, $this, 'endMap');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::BEGINMAP, $this, 'beginMap');
$this->maniaControl->getCallbackManager()
->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
// Settings
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN, false);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAPLIMIT_PLAYER, 1);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAPLIMIT_ADMIN, -1);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_BUFFERSIZE, 10);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE, true);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN, false);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MAPLIMIT_PLAYER, 1);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_MAPLIMIT_ADMIN, -1);
$this->maniaControl->getSettingManager()
->initSetting($this, self::SETTING_BUFFERSIZE, 10);
// Permissions
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CLEAR_MAPQUEUE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_QUEUE_BUFFER, AuthenticationManager::AUTH_LEVEL_ADMIN);
$this->maniaControl->getAuthenticationManager()
->definePermissionLevel(self::SETTING_PERMISSION_CLEAR_MAPQUEUE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager()
->definePermissionLevel(self::SETTING_PERMISSION_QUEUE_BUFFER, AuthenticationManager::AUTH_LEVEL_ADMIN);
// Admin Commands
$this->maniaControl->getCommandManager()->registerCommandListener(self::ADMIN_COMMAND_CLEAR_JUKEBOX, $this, 'command_ClearMapQueue', true, 'Clears the Map-Queue.');
$this->maniaControl->getCommandManager()->registerCommandListener(self::ADMIN_COMMAND_CLEAR_MAPQUEUE, $this, 'command_ClearMapQueue', true, 'Clears the Map-Queue.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('jb', 'jukebox', 'mapqueue'), $this, 'command_MapQueue', false, 'Shows current maps in Map-Queue.');
$this->maniaControl->getCommandManager()
->registerCommandListener(self::ADMIN_COMMAND_CLEAR_JUKEBOX, $this, 'command_ClearMapQueue', true, 'Clears the Map-Queue.');
$this->maniaControl->getCommandManager()
->registerCommandListener(self::ADMIN_COMMAND_CLEAR_MAPQUEUE, $this, 'command_ClearMapQueue', true, 'Clears the Map-Queue.');
$this->maniaControl->getCommandManager()
->registerCommandListener(array('jb', 'jukebox', 'mapqueue'), $this, 'command_MapQueue', false, 'Shows current maps in Map-Queue.');
}
/**
@ -88,7 +101,8 @@ class MapQueue implements CallbackListener, CommandListener {
* Add current map to buffer on startup
*/
public function handleAfterInit() {
$currentMap = $this->maniaControl->getMapManager()->getCurrentMap();
$currentMap = $this->maniaControl->getMapManager()
->getCurrentMap();
$this->buffer[] = $currentMap->uid;
}
@ -108,27 +122,34 @@ class MapQueue implements CallbackListener, CommandListener {
* @param Player $admin
*/
public function clearMapQueue(Player $admin) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
if (!$this->maniaControl->getAuthenticationManager()
->checkPermission($admin, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)
) {
$this->maniaControl->getAuthenticationManager()
->sendNotAllowed($admin);
return;
}
if (empty($this->queuedMaps)) {
$this->maniaControl->getChat()->sendError('$fa0There are no maps in the jukebox!', $admin->login);
$this->maniaControl->getChat()
->sendError('$fa0There are no maps in the jukebox!', $admin->login);
return;
}
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
$title = $this->maniaControl->getAuthenticationManager()
->getAuthLevelName($admin->authLevel);
//Destroy map - queue list
$this->queuedMaps = array();
$message = '$fa0' . $title . ' $<$fff' . $admin->nickname . '$> cleared the Map-Queue!';
$this->maniaControl->getChat()->sendInformation($message);
$this->maniaControl->getChat()
->sendInformation($message);
Logger::logInfo($message, true);
// Trigger callback
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('clear'));
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('clear'));
}
/**
@ -168,7 +189,8 @@ class MapQueue implements CallbackListener, CommandListener {
*/
public function showMapQueue(Player $player) {
if (empty($this->queuedMaps)) {
$this->maniaControl->getChat()->sendError('$fa0There are no maps in the jukebox!', $player->login);
$this->maniaControl->getChat()
->sendError('$fa0There are no maps in the jukebox!', $player->login);
return;
}
@ -179,7 +201,8 @@ class MapQueue implements CallbackListener, CommandListener {
$index++;
}
$this->maniaControl->getChat()->sendInformation($message, $player);
$this->maniaControl->getChat()
->sendInformation($message, $player);
}
/**
@ -189,7 +212,8 @@ class MapQueue implements CallbackListener, CommandListener {
*/
public function showMapQueueManialink(Player $player) {
if (empty($this->queuedMaps)) {
$this->maniaControl->getChat()->sendError('There are no Maps in the Jukebox!', $player);
$this->maniaControl->getChat()
->sendError('There are no Maps in the Jukebox!', $player);
return;
}
@ -198,7 +222,9 @@ class MapQueue implements CallbackListener, CommandListener {
array_push($maps, $queuedMap[1]);
}
$this->maniaControl->getMapManager()->getMapList()->showMapList($player, $maps);
$this->maniaControl->getMapManager()
->getMapList()
->showMapList($player, $maps);
}
/**
@ -233,13 +259,15 @@ class MapQueue implements CallbackListener, CommandListener {
* @param string $uid
*/
public function addMapToMapQueue($login, $uid) {
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
$player = $this->maniaControl->getPlayerManager()
->getPlayer($login);
if (!$player) {
return;
}
//Check if player is allowed to add (another) map
$isModerator = $this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$isModerator = $this->maniaControl->getAuthenticationManager()
->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$mapsForPlayer = 0;
foreach ($this->queuedMaps as $queuedMap) {
@ -249,15 +277,19 @@ class MapQueue implements CallbackListener, CommandListener {
}
if ($isModerator) {
$maxAdmin = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAPLIMIT_ADMIN);
$maxAdmin = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MAPLIMIT_ADMIN);
if ($maxAdmin >= 0 && $mapsForPlayer >= $maxAdmin) {
$this->maniaControl->getChat()->sendError('You already have $<$fff' . $maxAdmin . '$> map(s) in the Map-Queue!', $login);
$this->maniaControl->getChat()
->sendError('You already have $<$fff' . $maxAdmin . '$> map(s) in the Map-Queue!', $login);
return;
}
} else {
$maxPlayer = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAPLIMIT_PLAYER);
$maxPlayer = $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_MAPLIMIT_PLAYER);
if ($maxPlayer >= 0 && $mapsForPlayer >= $maxPlayer) {
$this->maniaControl->getChat()->sendError('You already have $<$fff' . $maxPlayer . '$> map(s) in the Map-Queue!', $login);
$this->maniaControl->getChat()
->sendError('You already have $<$fff' . $maxPlayer . '$> map(s) in the Map-Queue!', $login);
return;
}
}
@ -269,29 +301,36 @@ class MapQueue implements CallbackListener, CommandListener {
$uid = $map->uid;
}
if (array_key_exists($uid, $this->queuedMaps)) {
$this->maniaControl->getChat()->sendError('That map is already in the Map-Queue!', $login);
$this->maniaControl->getChat()
->sendError('That map is already in the Map-Queue!', $login);
return;
}
//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)) {
$this->maniaControl->getChat()->sendError('That map has recently been played!', $login);
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
$this->maniaControl->getChat()
->sendError('That map has recently been played!', $login);
if (!$this->maniaControl->getAuthenticationManager()
->checkPermission($player, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)
) {
return;
}
}
if (!$map) {
$map = $this->maniaControl->getMapManager()->getMapByUid($uid);
$map = $this->maniaControl->getMapManager()
->getMapByUid($uid);
}
$this->queuedMaps[$uid] = array($player, $map);
$this->maniaControl->getChat()->sendInformation('$fa0$<$fff' . $map->name . '$> has been added to the Map-Queue by $<$fff' . $player->nickname . '$>.');
$this->maniaControl->getChat()
->sendInformation('$fa0$<$fff' . $map->name . '$> has been added to the Map-Queue by $<$fff' . $player->nickname . '$>.');
// Trigger callback
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('add', $this->queuedMaps[$uid]));
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('add', $this->queuedMaps[$uid]));
}
/**
@ -308,10 +347,12 @@ class MapQueue implements CallbackListener, CommandListener {
$map = $this->queuedMaps[$uid][1];
unset($this->queuedMaps[$uid]);
$this->maniaControl->getChat()->sendInformation('$fa0$<$fff' . $map->name . '$> is removed from the Map-Queue by $<$fff' . $player->nickname . '$>.');
$this->maniaControl->getChat()
->sendInformation('$fa0$<$fff' . $map->name . '$> is removed from the Map-Queue by $<$fff' . $player->nickname . '$>.');
// Trigger callback
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('remove', $map));
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('remove', $map));
}
/**
@ -327,7 +368,9 @@ class MapQueue implements CallbackListener, CommandListener {
}
$this->nextMap = null;
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SKIP_MAP_ON_LEAVE)) {
if ($this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_SKIP_MAP_ON_LEAVE)
) {
// Skip Map if requester has left
foreach ($this->queuedMaps as $queuedMap) {
$player = $queuedMap[0];
@ -338,11 +381,15 @@ class MapQueue implements CallbackListener, CommandListener {
}
// Player found, so play this map
if ($this->maniaControl->getPlayerManager()->getPlayer($player->login)) {
if ($this->maniaControl->getPlayerManager()
->getPlayer($player->login)
) {
break;
}
if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SKIP_MAPQUEUE_ADMIN)) {
if (!$this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_SKIP_MAPQUEUE_ADMIN)
) {
//Check if the queuer is a admin
if ($player->authLevel > 0) {
break;
@ -350,12 +397,14 @@ class MapQueue implements CallbackListener, CommandListener {
}
// Trigger callback
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('skip', $queuedMap[0]));
$this->maniaControl->getCallbackManager()
->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('skip', $queuedMap[0]));
// Player not found, so remove the map from the mapqueue
array_shift($this->queuedMaps);
$this->maniaControl->getChat()->sendInformation('$fa0$<$fff' . $queuedMap[0]->name . '$> is skipped because $<' . $player->nickname . '$> left the game!');
$this->maniaControl->getChat()
->sendInformation('$fa0$<$fff' . $queuedMap[0]->name . '$> is skipped because $<' . $player->nickname . '$> left the game!');
}
}
@ -367,10 +416,12 @@ class MapQueue implements CallbackListener, CommandListener {
}
$map = $this->nextMap[1];
/** @var Map $map */
$this->maniaControl->getChat()->sendInformation('$fa0Next map will be $<$fff' . $map->name . '$> as requested by $<' . $this->nextMap[0]->nickname . '$>.');
$this->maniaControl->getChat()
->sendInformation('$fa0Next map will be $<$fff' . $map->name . '$> as requested by $<' . $this->nextMap[0]->nickname . '$>.');
try {
$this->maniaControl->getClient()->setNextMapIdent($map->uid);
$this->maniaControl->getClient()
->setNextMapIdent($map->uid);
} catch (NextMapException $e) {
} catch (NotInListException $e) {
}
@ -386,7 +437,9 @@ class MapQueue implements CallbackListener, CommandListener {
return;
}
if (count($this->buffer) >= $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_BUFFERSIZE)) {
if (count($this->buffer) >= $this->maniaControl->getSettingManager()
->getSettingValue($this, self::SETTING_BUFFERSIZE)
) {
array_shift($this->buffer);
}