jasonw4331 / libpmquery
用于查询Minecraft基岩服务器的库
1.0.0
2024-04-22 19:39 UTC
Requires
- php: ^7.4|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.11
- phpstan/extension-installer: ^1.3.0
- phpstan/phpstan: ^1.10.14
- phpstan/phpstan-strict-rules: ^1.5.1
This package is auto-updated.
Last update: 2024-09-28 13:30:24 UTC
README
一个PocketMine病毒,允许插件查询其他服务器以获取所选信息
基本用法
这个病毒是为开发者轻松查询Pocketmine-MP服务器而制作的。以下是一些基本功能
必需导入
以下导入对于使用病毒库是必要的
use jasonw4331\libpmquery\PMQuery; use jasonw4331\libpmquery\PmQueryException;
API
查询API是一个单一功能,它从您输入的任何服务器中获取数据。用法如下
$query = PMQuery::query("my.server.net", 19132);
返回的值将遵循以下值/类型
$query['GameName']; // Returns the server software being used $query['HostName']; // Returns the server host name $query['Protocol']; // Returns the protocol version allowed to connect $query['Version']; // Returns the client version allowed to connect $query['Players']; // Returns the number of players on the server currently $query['MaxPlayers']; // Returns the maximum player count of the server $query['ServerId']; // Returns the raknet server id $query['Map']; // Returns the default world name $query['GameMode']; // Returns the default gamemode $query['NintendoLimited']; // Returns the status of Nintendo's limitation to join $query['IPv4Port']; // Returns the ipv4 port number $query['IPv6Port']; // Returns the ipv6 port number $query['Extra']; // I still don't know what this info is
离线查询
发送到离线服务器的查询总是会抛出 PmQueryException
。异常可以在try/catch语句中捕获以记录其离线状态。
try{ $query = PMQuery::query("my.server.net", 19133); $players = (int) $query['Players']; Server::getInstance()->getLogger()->info("There are ".$players." on the queried server right now!"); }catch(PmQueryException $e){ //you can choose to log this if you want Server::getInstance()->getLogger()->info("The queried server is offline right now!"); }