coding & phpdoc improvements continued

This commit is contained in:
Steffen Schröder 2014-05-27 22:44:22 +02:00
parent 9e016cc770
commit c284feb843
12 changed files with 23 additions and 40 deletions

View File

@ -671,7 +671,6 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
public function updateWidget() { public function updateWidget() {
$players = $this->maniaControl->playerManager->getPlayers(); $players = $this->maniaControl->playerManager->getPlayers();
foreach ($players as $player) { foreach ($players as $player) {
/** @var Player $player */
$currentPage = $player->getCache($this, self::CACHE_CURRENT_PAGE); $currentPage = $player->getCache($this, self::CACHE_CURRENT_PAGE);
if ($currentPage !== null) { if ($currentPage !== null) {
$this->showMapList($player, null, $currentPage); $this->showMapList($player, null, $currentPage);

View File

@ -175,8 +175,6 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$pageFrame = null; $pageFrame = null;
foreach ($players as $listPlayer) { foreach ($players as $listPlayer) {
/** @var Player $listPlayer * */
if ($i % self::MAX_PLAYERS_PER_PAGE === 1) { if ($i % self::MAX_PLAYERS_PER_PAGE === 1) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);

View File

@ -40,6 +40,7 @@ class PlayerManager implements CallbackListener, TimerListener {
public $playerDetailed = null; public $playerDetailed = null;
public $playerList = null; public $playerList = null;
public $adminLists = null; public $adminLists = null;
/** @var Player[] $players */
public $players = array(); public $players = array();
/* /*
@ -296,10 +297,12 @@ class PlayerManager implements CallbackListener, TimerListener {
* @return int * @return int
*/ */
public function getPlayerCount($withoutSpectators = true) { public function getPlayerCount($withoutSpectators = true) {
if (!$withoutSpectators) {
return count($this->players);
}
$count = 0; $count = 0;
foreach ($this->players as $player) { foreach ($this->players as $player) {
/** @var Player $player */ if (!$player->isSpectator) {
if (!$player->isSpectator || !$withoutSpectators) {
$count++; $count++;
} }
} }
@ -413,7 +416,7 @@ class PlayerManager implements CallbackListener, TimerListener {
/** /**
* Get all Players * Get all Players
* *
* @return array * @return Player[]
*/ */
public function getPlayers() { public function getPlayers() {
return $this->players; return $this->players;
@ -427,7 +430,6 @@ class PlayerManager implements CallbackListener, TimerListener {
public function getSpectatorCount() { public function getSpectatorCount() {
$count = 0; $count = 0;
foreach ($this->players as $player) { foreach ($this->players as $player) {
/** @var Player $player */
if ($player->isSpectator) { if ($player->isSpectator) {
$count++; $count++;
} }
@ -436,15 +438,14 @@ class PlayerManager implements CallbackListener, TimerListener {
} }
/** /**
* Gets a Player by his index * Gets a Player by his Index
* *
* @param int $index * @param int $index
* @param bool $connectedPlayersOnly * @param bool $connectedPlayersOnly
* @return Player|null * @return Player
*/ */
public function getPlayerByIndex($index, $connectedPlayersOnly = false) { public function getPlayerByIndex($index, $connectedPlayersOnly = false) {
foreach ($this->players as $player) { foreach ($this->players as $player) {
/** @var Player $player */
if ($player->index == $index) { if ($player->index == $index) {
return $player; return $player;
} }

View File

@ -29,7 +29,9 @@ class PluginManager {
private $maniaControl = null; private $maniaControl = null;
private $pluginMenu = null; private $pluginMenu = null;
private $pluginInstallMenu = null; private $pluginInstallMenu = null;
/** @var Plugin[] $activePlugins */
private $activePlugins = array(); private $activePlugins = array();
/** @var string[] $pluginClasses */
private $pluginClasses = array(); private $pluginClasses = array();
/** /**

View File

@ -215,8 +215,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
public function each5Seconds() { public function each5Seconds() {
// Empty shutdown // Empty shutdown
if ($this->serverShutdownEmpty) { if ($this->serverShutdownEmpty) {
$players = $this->maniaControl->playerManager->getPlayers(); if ($this->maniaControl->playerManager->getPlayerCount(false) <= 0) {
if (count($players) <= 0) {
$this->shutdownServer('empty'); $this->shutdownServer('empty');
} }
} }

View File

@ -110,7 +110,7 @@ class StatisticCollector implements CallbackListener {
*/ */
public function onEndMap(array $callback) { public function onEndMap(array $callback) {
//Check for Minimum PlayerCount //Check for Minimum PlayerCount
if (count($this->maniaControl->playerManager->getPlayers()) < $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_COLLECT_STATS_MINPLAYERS)) { if ($this->maniaControl->playerManager->getPlayerCount() < $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_COLLECT_STATS_MINPLAYERS)) {
return; return;
} }
@ -149,13 +149,13 @@ class StatisticCollector implements CallbackListener {
*/ */
public function handleCallbacks(array $callback) { public function handleCallbacks(array $callback) {
//TODO survivals //TODO survivals
//Check if Stat Collecting is enabled // Check if Stat Collecting is enabled
if (!$this->maniaControl->settingManager->getSettingValue($this, self::SETTING_COLLECT_STATS_ENABLED)) { if (!$this->maniaControl->settingManager->getSettingValue($this, self::SETTING_COLLECT_STATS_ENABLED)) {
return; return;
} }
//Check for Minimum PlayerCount // Check for Minimum PlayerCount
if (count($this->maniaControl->playerManager->getPlayers()) < $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_COLLECT_STATS_MINPLAYERS)) { if ($this->maniaControl->playerManager->getPlayerCount() < $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_COLLECT_STATS_MINPLAYERS)) {
return; return;
} }

View File

@ -268,7 +268,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
// No update available // No update available
return; return;
} }
if (count($this->maniaControl->playerManager->getPlayers()) > 0) { if ($this->maniaControl->playerManager->getPlayerCount(false) > 0) {
// Server not empty // Server not empty
return; return;
} }

View File

@ -146,10 +146,9 @@ class ChatMessagePlugin implements CommandListener, Plugin {
* @return mixed * @return mixed
*/ */
private function getTarget($login) { private function getTarget($login) {
/** @var Player $player */
$player = null; $player = null;
foreach ($this->maniaControl->playerManager->getPlayers() as $player) { foreach ($this->maniaControl->playerManager->getPlayers() as $player) {
if ($login == $player && $login == $player->login || $login == $player->pid || $login == $player->nickname) { if ($login == $player || $login == $player->login || $login == $player->pid || $login == $player->nickname) {
return $player->nickname; return $player->nickname;
} }
} }

View File

@ -305,7 +305,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
return null; return null;
} }
if (count($this->maniaControl->playerManager->getPlayers()) == 0) { if ($this->maniaControl->playerManager->getPlayerCount(false) <= 0) {
return null; return null;
} }
@ -326,7 +326,6 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
} }
$playerInfo = array(); $playerInfo = array();
foreach ($players as $player) { foreach ($players as $player) {
/** @var Player $player */
array_push($playerInfo, array('Login' => $player->login, 'IsSpec' => $player->isSpectator)); array_push($playerInfo, array('Login' => $player->login, 'IsSpec' => $player->isSpectator));
} }
return $playerInfo; return $playerInfo;

View File

@ -362,7 +362,6 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$properties['getvotesonly'] = false; $properties['getvotesonly'] = false;
$properties['playerlogins'] = array(); $properties['playerlogins'] = array();
foreach ($this->maniaControl->playerManager->getPlayers() as $loopPlayer) { foreach ($this->maniaControl->playerManager->getPlayers() as $loopPlayer) {
/** @var Player $loopPlayer */
$properties['playerlogins'][] = $loopPlayer->login; $properties['playerlogins'][] = $loopPlayer->login;
} }
} else { } else {

View File

@ -400,7 +400,6 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$this->resetRanks(); $this->resetRanks();
foreach ($this->maniaControl->playerManager->getPlayers() as $player) { foreach ($this->maniaControl->playerManager->getPlayers() as $player) {
/** @var Player $player */
if ($player->isFakePlayer()) { if ($player->isFakePlayer()) {
continue; continue;
} }

View File

@ -306,25 +306,13 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
$backgroundQuad->setSize($width, $height); $backgroundQuad->setSize($width, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$maxPlayers = $this->maniaControl->client->getMaxPlayers();
$maxSpectators = $this->maniaControl->client->getMaxSpectators();
$serverName = $this->maniaControl->client->getServerName(); $serverName = $this->maniaControl->client->getServerName();
$players = $this->maniaControl->playerManager->getPlayers(); $playerCount = $this->maniaControl->playerManager->getPlayerCount(true);
$playerCount = 0; $maxPlayers = $this->maniaControl->client->getMaxPlayers();
$spectatorCount = 0;
/** $spectatorCount = $this->maniaControl->playerManager->getSpectatorCount();
* @var Player $player $maxSpectators = $this->maniaControl->client->getMaxSpectators();
*/
foreach ($players as $player) {
if ($player->isSpectator) {
$spectatorCount++;
} else {
$playerCount++;
}
}
$label = new Label_Text(); $label = new Label_Text();
$frame->add($label); $frame->add($label);