I'm trying to get online players to the current server using UI. My current code only shows 0 when there players online. PHP: $button = new Button(TextFormat::GREEN . "Factions" . "\n" . TextFormat::GREEN . count(Server::getInstance()->getOnlinePlayers())); $ui->addButton($button);
PHP: $playersOnline = count($this->getServer()->getOnlinePlayers());$maxOnline = $this->getServer()->getMaxPlayers();$button = new Button(TextFormat::GREEN . "Factions" . "\n" . TextFormat::GREEN . $playersOnline . "/" . $maxOnline ); If you want to refresh player Count, use the Task PHP: public function onEnable(){ $this->getServer()->getScheduler()->scheduleRepeatingTask(new TTask($this), 4); //refresh every 5ticks }class TTask extends PluginTask{ public function onRun(int $currentTick){ $this->getOwner()->reloadUIs(); //reloadUIs or Function name//reloadUIs if you use CustomUI by XenialDan }}
An other away http://mcapi.ca/query/fac-symphonia.eu/mcpe http://mcapi.ca/query/$servIP/mcpe/$servPORT