Hello I want this code here PHP: $CC = count($this->getServer()->getLevelByName("World")->getPlayers()); To add more worlds so it can count all once for my minigame plugin NPC.
PHP: /** * @return int */ public function cc(): int { return count($this->getServer()->getLevelByName("Disney")->getPlayers()) + count($this->getServer()->getLevelByName("World")->getPlayers()) + count...; }// $this->cc();
some examples: PHP: public function getPlayersOnWorld() : int { return count($this->getServer()->getOnlinePlayers()); } PHP: public function getPlayersOnSpecifyWorlds() : int{ $worlds = ["world", "minigame1", "minigame2"]; $playersCount = 0; foreach($worlds as $world) $playersCount += count($this->getServer()->getLevelByName($world)->getPlayers()); return $playersCount; }
More efficient function: PHP: public function getWorldsPlayerCount(array $worlds) : int{ $playersCount = 0; foreach($worlds as $world) $playersCount += count($this->getServer()->getLevelByName($world)->getPlayers()); return $playersCount; } Usage: PHP: $this->getWorldsPlayerCount(["myworld","myotherworld"]);// Returns worlds player count