Hi I'm trying to get this line to work but it keeps returning the error: Fatal error: Call to a member function getPlayers() on null Here's the code: PHP: $online = count($this->plugin->getServer()->getLevelByName($world)->getPlayers()); The $world variable is already declared. Any suggestions? -Calrizer
Try this it should work ! (If $world is already declared !) PHP: $online = count($this->plugin->getServer()->getLevelByName($world)->getPlayer());//You just have to remove the "s" at players ! Because getPlayers(); doesn't exists only but getPlayer(); work ! Quote me i f you need help !
I have antoher idea but don't know if it work : PHP: foreach($this->plugin->getPlayer()->getLevel($world)->getPlayers() as $levelplayers){$online = $levelplayers;}
$world is declared but it may not contain a valid level name. Note that if you are under Windows, case may be not be significant, but it is in PocketMien. Anyway, getLevelByName is returning null (couldn't find the world you requested), so getPlayers() fails.
PHP: $temp = [];foreach($this->getServer()->getOnlinePlayers() as $p){ if($p->getLevel()->getName() === $world){ $temp[] = $p->getName(); }}$value = count($temp); im not sure if this works but i find this more logical xD
Do you understand PHP... Didn't you see we are talking about context of a Level? If it's 12:20 there and you can't think, don't post without thinking