added withoutbots to getplayercount

This commit is contained in:
kremsy
2015-06-21 20:55:10 +02:00
parent 12e72c7398
commit 1c06e7ff6e
2 changed files with 17 additions and 5 deletions

View File

@ -382,15 +382,24 @@ class PlayerManager implements CallbackListener, TimerListener, EchoListener {
* Get the count of all Players
*
* @param bool $withoutSpectators
* @param bool $withoutBots
* @return int
*/
public function getPlayerCount($withoutSpectators = true) {
if (!$withoutSpectators) {
return count($this->players);
}
public function getPlayerCount($withoutSpectators = true, $withoutBots = true) {
$count = 0;
foreach ($this->players as $player) {
if (!$player->isSpectator) {
$valid = true;
if ($withoutSpectators) {
if ($player->isSpectator) {
$valid = false;
}
}
if ($withoutBots) {
if ($player->isFakePlayer()) {
$valid = false;
}
}
if ($valid) {
$count++;
}
}