hi i have a multi server server and i need a plugin that show the online players on the slappers and in the scorehud how can i make it?
PHP: const LINK_ONLINE = 'https://minecraft-api.com/api/query/playeronline.php?ip=[IP]&port=[PORT]';/**@Param Server IP $ip*@Param Server Port $port*/public function getOnlineServerPlayers(string $ip, int $port) : int{ $result = str_replace(["[IP]", "[PORT]"], [$ip, $port], self::LINK_ONLINE); $online = \pocketmine\utils\Internet::getURL($result); return is_int($online) ? $online : 0;}
Note that this will hang your server while doing the HTTP request, if you don't want that you can either manually put that into an AsyncTask or use PM's BulkCurlTask (see https://github.com/HimbeersaftLP/Li.../src/Himbeer/LibSkin/SkinGatherer.php#L32-L53 for an example)
PHP: $online = (int)file_get_contents("https://minecraft-api.com/api/query/playeronline.php?ip=[IP]&port=[PORT]");
To do this, you need to make a new addon, which should be located in the plugin_data folder. You have to make a new add-on, and you will also need some logic to do this (not trying to offend anyone here!) This is what I have made for my server: PHP: <?phpdeclare(strict_types = 1);/** * @name KitPvP * @version 1.0.0 * @main JackMD\ScoreHud\Addons\KitPvP */namespace JackMD\ScoreHud\Addons{ use JackMD\ScoreHud\addon\AddonBase; use pocketmine\Player; use pocketmine\utils\Internet; use pocketmine\Server; class KitPvP extends AddonBase{ const LINK_ONLINE = 'https://minecraft-api.com/api/query/playeronline.php?ip=[IP]&port=[PORT]'; /** * @param Player $player * @return array */ public function getProcessedTags(Player $player): array{ $online = (int)file_get_contents("https://minecraft-api.com/api/query/playeronline.php?ip=51.79.76.77&port=41021"); return [ "{kitpvp}" => $online ]; } /* *@Param Server IP $ip *@Param Server Port $port */ /* public function getOnlineServerPlayers(string $ip, int $port) : int{ $result = str_replace(["51.79.76.77", "41021"], [$ip, $port], self::LINK_ONLINE); $online = \pocketmine\utils\Internet::getURL($result); return is_int($online) ? $online : 0; } */ } } The file name is KitPvP.php, which is why the class is also called KitPvP, and why the name in the note (necessary for some reason) is KitPvP. Please keep in note: This will stop your server occasionally (unnoticeable) becuase it will attempt to retrieve the files from Minecraft's API. P.S: Check out my kitpvp server if you don't mind (SORRY LMAOOO) ~ Ethaniccc </3
Haven't figured out how to do that with the Scoreboard Addons yet, if you could help me with that? When I made the Scoreboard plugin above (check my other comment for reference), I noticed it would like do a mini-stop on my server while doing the HTTP request. By any chance could you help me?
Feel free to copy the function from my virion above and then use it like this: PHP: asyncHttpGetRequest("https://minecraft-api.com/api/query/playeronline.php?ip=51.79.76.77&port=41021", function ($response) { $body = $response[0];});