mops1k/minecraftserverstatus

Minecraft 服务器状态查询,使用 PHP 编写,包含在线玩家、motd、favicon 以及更多服务器相关信息,无需插件和启用查询。

1.0.1 2017-02-04 22:26 UTC

This package is auto-updated.

Last update: 2024-08-29 04:58:28 UTC


README

#Minecraft 服务器状态

Minecraft 服务器状态,用于查询在线玩家、motd、favicon 以及更多服务器相关信息的库,无需插件和启用查询。

*已在 Spigot 1.11 上进行测试

安装

composer require mops1k/minecraftserverstatus

###教程

<?php
use MinecraftServerStatus\MinecraftServerStatus;

require '../vendor/autoload.php';

$status = new MinecraftServerStatus();
$status
    ->setHost('localhost')
    ->setPort(25565)
;

if (!$status->query()) {
    echo "The Server is offline!";
} else {
    $data = $status->getData();

    if ($data->getFavicon()) {
        echo "<img width=\"64\" height=\"64\" src=\"" . $data->getFavicon() . "\" /> <br>";
    }
    echo "The Server " . $data->getHostname() . " is running on " . $data->getVersion() . " and is online,
		currently are " . $data->getPlayers() . " players online
		of a maximum of " . $data->getMaxPlayers() . ". The motd of the server is '" . $data->getDescription() . "'.
		The server has a ping of " . $data->getPing() . " milliseconds.";
}

如果服务器离线,$status->query() 返回 false,否则返回 true,并将服务器信息填充到 $status->getData() 中。