josantonius / minecraft-server-player-stat
PHP 库,用于获取 Minecraft 服务器上玩家的实时统计数据。
Requires
- php: ^8.1
Requires (Dev)
- josantonius/json: ^v2.0
- phpmd/phpmd: ^2.6
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
This package is auto-updated.
Last update: 2023-06-16 00:10:32 UTC
README
翻译: 西班牙语
PHP 库,用于获取 Minecraft 服务器上玩家的实时统计数据。
需求
-
此库与 PHP 版本 8.1 兼容。
-
Minecraft 服务器: Spigot。
-
Minecraft 版本: 1.17。
-
操作系统: Linux | Windows。
相关细节
-
此库是为从 PHP 命令行 (CLI) 运行的应用程序开发的,特别是为了支持一个显示实时玩家统计数据的 Twitch 机器人。虽然它也可以在 Web 环境中使用,但我不推荐这样做。
-
它可能适用于 Spigot 服务器的新版本,但无法确定,因为它仅与上述需求进行了测试。欢迎为其他服务器或 Minecraft 版本添加新的测试。
-
可用的术语来自 minecraft-assets 仓库,由 InventivetalentDev 提供。
安装
安装此扩展的首选方式是通过 Composer。
要安装 PHP Minecraft 服务器玩家统计库,请按以下步骤操作
composer require josantonius/minecraft-server-player-stat
前面的命令只会安装必要的文件,如果您想 下载整个源代码,可以使用
composer require josantonius/minecraft-server-player-stat --prefer-source
您还可以使用 Git 克隆整个仓库
git clone https://github.com/josantonius/php-minecraft-server-player-stat.git
可用类
MinecraftServer 类
Josantonius\MinecraftServerPlayerStat\MinecraftServer
为 Minecraft 服务器创建一个新的实例
/** * @param string $version Server version. * @param string $language Server language. * @param string $logsPath Server logs directory path. * @param string $statsPath Server stats directory path. * @param string $storagePath Directory path where available terms and players will be stored. * * @throws MinecraftServerException if the Minecraft version or language is not valid. * @throws UnreadableDirectoryException if the logs or stats path is not valid. * @throws UnwriteableDirectoryException if the storage path is not valid. * * @see https://mcasset.cloud/1.19.2/assets/minecraft/lang to see available languages. */ public function __construct( private string $version, private string $language, private string $logsPath, private string $statsPath, private string $storagePath, );
获取特定玩家统计信息的详细信息
/** * @param string $username Username in case insensitive. * @param string $term Literal Minecraft term in case insensitive. * In Spanish, a term with accents can be written without them. * For another languages accents are required. * * @throws WrongTermException if the term is not valid. * @throws StatsNotFoundException if the stats file is not found. * @throws UnknownUsernameException if the username is not valid. */ public function getPlayerStat(string $username, string $term): MinecraftPlayerStat;
获取可用统计信息的列表
public function getAvailableStats(): array;
从服务器获取玩家列表
public function getPlayerList(): array;
MinecraftPlayerStat 实例
Josantonius\MinecraftServerPlayerStat\MinecraftPlayerStat
损坏的物品数量,如果没有统计数据则为 null
public readonly int|null $broken;
制作的物品数量,如果没有统计数据则为 null
public readonly int|null $crafted;
掉落的物品数量,如果没有统计数据则为 null
public readonly int|null $dropped;
被怪物击杀的怪物数量,如果没有统计数据则为 null
public readonly int|null $killed;
被怪物击杀的数量,如果没有统计数据则为 null
public readonly int|null $killedBy;
挖掘的物品数量,如果没有统计数据则为 null
public readonly int|null $mined;
捡起的物品数量,如果没有统计数据则为 null
public readonly int|null $pickedUp;
使用的物品数量,如果没有统计数据则为 null
public readonly int|null $used;
自定义统计值,如果没有统计数据则为 null
/** * If the unit type is distance, this value is given in centimeters. * If the unit type is time, this value is given in ticks. * * @see https://minecraft.fandom.com/wiki/Tutorials/Units_of_measure to see the unit conversions. */ public readonly int|null $custom;
术语的清洁键
public readonly string $key;
以优雅的方式表达的术语
public readonly string $prettyTerm;
查询术语
public readonly string $term;
项目类型
/** * Available types: block, entity, item, stat. */ public readonly string $type;
单位类型
/** * Available types: amount, distance, time. */ public readonly string $unitType;
查询的账户名
public readonly string $username;
查询的账户UUID
public readonly string $uuid;
使用的异常
此库的用法示例
use Josantonius\MinecraftServerPlayerStat\Exceptions\WrongTermException; use Josantonius\MinecraftServerPlayerStat\Exceptions\StatsNotFoundException; use Josantonius\MinecraftServerPlayerStat\Exceptions\UnknownUsernameException; use Josantonius\MinecraftServerPlayerStat\Exceptions\MinecraftServerException; use Josantonius\MinecraftServerPlayerStat\Exceptions\UnreadableDirectoryException; use Josantonius\MinecraftServerPlayerStat\Exceptions\UnwriteableDirectoryException;
用法
获取关于方块的游戏者统计数据
use Josantonius\MinecraftServerPlayerStat\MinecraftServer; $minecraftServer = new MinecraftServer( version: '1.17.1', language: 'it_it', logsPath: '/minecraft/logs', statsPath: '/minecraft/saves/world/stats', storagePath: '/data/storage', ); $stat = $minecraftServer->getPlayerStat('Aguilar11235813', 'Blocco Di Diamante'); echo "{$stat->username} ha raccolto {$stat->pickedUp} blocchi di diamante."; // Aguilar11235813 ha raccolto 8 blocchi di diamanti.
MinecraftPlayerStat $stat
object(Josantonius\MinecraftServerPlayerStat\MinecraftPlayerStat) { 'broken' => NULL, 'crafted' => NULL, 'custom' => NULL, 'dropped' => NULL, 'killed' => NULL, 'killedBy' => NULL, 'mined' => 8, 'pickedUp' => 8, 'used' => NULL, 'key' => 'diamond_block', 'prettyTerm' => 'Blocco di diamante', 'term' => 'Blocco Di Diamante', 'type' => 'block', 'unitType' => 'amount', 'username' => 'Aguilar11235813', 'uuid' => '18f154fe-3678-37e9-9b77-185e0bfe446d', }
获取关于距离的游戏者统计数据
use Josantonius\MinecraftServerPlayerStat\MinecraftServer; $minecraftServer = new MinecraftServer( version: '1.19.1', language: 'es_es', logsPath: '/minecraft/logs', statsPath: '/minecraft/saves/world/stats', storagePath: '/data/storage', ); $stat = $minecraftServer->getPlayerStat('Armadillo', 'Distancia Volada'); echo "{$stat->username} voló una distancia de " . cmToKm($stat->custom) . ' kilómetros.'; // Armadillo voló una distancia de 6 kilómetros.
MinecraftPlayerStat $stat
object(Josantonius\MinecraftServerPlayerStat\MinecraftPlayerStat) { 'broken' => NULL, 'crafted' => NULL, 'custom' => 585888, // centimeters 'dropped' => NULL, 'killed' => NULL, 'killedBy' => NULL, 'mined' => NULL, 'pickedUp' => NULL, 'used' => NULL, 'key' => 'fly_one_cm', 'prettyTerm' => 'Distancia volada', 'term' => 'Distancia Volada', 'type' => 'stat', 'unitType' => 'distance', 'username' => 'Armadillo', 'uuid' => '14e55460-c753-31f2-bd0a-c305e2ff34b5', }
获取关于实体的游戏者统计数据
use Josantonius\MinecraftServerPlayerStat\MinecraftServer; $minecraftServer = new MinecraftServer( version: '1.17', language: 'en_us', logsPath: '/minecraft/logs', statsPath: '/minecraft/saves/world/stats', storagePath: '/data/storage', ); $stat = $minecraftServer->getPlayerStat('KrakenBite', 'zombie'); echo "{$stat->username} was killed {$stat->killedBy} times by a {$stat->term}."; // KrakenBite was killed 2 times by a zombie.
MinecraftPlayerStat $stat
object(Josantonius\MinecraftServerPlayerStat\MinecraftPlayerStat) { 'broken' => NULL, 'crafted' => NULL, 'custom' => NULL, 'dropped' => NULL, 'killed' => 8, 'killedBy' => 2, 'mined' => NULL, 'pickedUp' => NULL, 'used' => NULL, 'key' => 'zombie', 'prettyTerm' => 'Zombie', 'term' => 'zombie', 'type' => 'entity', 'unitType' => 'amount', 'username' => 'KrakenBite', 'uuid' => '5cd5d2e7-9b3a-3f06-befb-34f7a81b14c6', }
获取关于物品的游戏者统计数据
use Josantonius\MinecraftServerPlayerStat\MinecraftServer; $minecraftServer = new MinecraftServer( version: '1.18.1', language: 'fr_fr', logsPath: '/minecraft/logs', statsPath: '/minecraft/saves/world/stats', storagePath: '/data/storage', ); $stat = $minecraftServer->getPlayerStat('Tweedlex', 'HACHE ON BOIS'); echo "{$stat->username} a utilisé une " . strtolower($stat->term) . " {$stat->used} fois."; // Tweedlex a utilisé une hache en bois 111 fois.
MinecraftPlayerStat $stat
object(Josantonius\MinecraftServerPlayerStat\MinecraftPlayerStat) { 'broken' => 8, 'crafted' => 8, 'custom' => NULL, 'dropped' => NULL, 'killed' => NULL, 'killedBy' => NULL, 'mined' => NULL, 'pickedUp' => NULL, 'used' => 111, 'key' => 'wooden_axe', 'prettyTerm' => 'Hache en bois', 'term' => 'HACHE ON BOIS', 'type' => 'item', 'unitType' => 'amount', 'username' => 'Tweedlex', 'uuid' => '8cb86072-3472-3b86-90f2-1e11b7188197', }
获取关于时间的游戏者统计数据
use Josantonius\MinecraftServerPlayerStat\MinecraftServer; $minecraftServer = new MinecraftServer( version: '1.19.2', language: 'pt_br', logsPath: '/minecraft/logs', statsPath: '/minecraft/saves/world/stats', storagePath: '/data/storage', ); $stat = $minecraftServer->getPlayerStat('SpOok', 'tempo desde a última morte'); echo 'SpOok morreu pela última vez há ' . ticksToHour($stat->custom) . ' horas.'; // SpOok morreu pela última vez há 10 horas.
MinecraftPlayerStat $stat
object(Josantonius\MinecraftServerPlayerStat\MinecraftPlayerStat) { 'broken' => NULL, 'crafted' => NULL, 'custom' => 720000, // ticks 'dropped' => NULL, 'killed' => NULL, 'killedBy' => NULL, 'mined' => NULL, 'pickedUp' => NULL, 'used' => NULL, 'key' => 'time_since_death', 'prettyTerm' => 'Tempo desde a última morte', 'term' => 'tempo desde a última morte', 'type' => 'stat', 'unitType' => 'time', 'username' => 'SpOok', 'uuid' => '8d5b923d-37fb-38d1-8a6a-a17cd5ccf768', }
获取可用统计数据列表
use Josantonius\MinecraftServerPlayerStat\MinecraftServer; $minecraftServer = new MinecraftServer( version: '1.17.1', language: 'en_us', logsPath: '/minecraft/logs', statsPath: '/minecraft/saves/world/stats', storagePath: '/data/storage', ); $terms = $minecraftServer->getAvailableStats();
$terms
[ /* ... */ 'zombie spawn egg' => [ 'key' => 'zombie_spawn_egg', 'pretty_term' => 'Zombie Spawn Egg', 'type' => 'item', 'unit_type' => 'amount', ], 'zombie villager' => [ 'key' => 'zombie_villager', 'pretty_term' => 'Zombie Villager', 'type' => 'entity', 'unit_type' => 'amount', ], 'zombie villager spawn egg' => [ 'key' => 'zombie_villager_spawn_egg', 'pretty_term' => 'Zombie Villager Spawn Egg', 'type' => 'item', 'unit_type' => 'amount', ], 'zombie wall head' => [ 'key' => 'zombie_wall_head', 'pretty_term' => 'Zombie Wall Head', 'type' => 'block', 'unit_type' => 'amount', ], 'zombified piglin' => [ 'key' => 'zombified_piglin', 'pretty_term' => 'Zombified Piglin', 'type' => 'entity', 'unit_type' => 'amount', ], 'zombified piglin spawn egg' => [ 'key' => 'zombified_piglin_spawn_egg', 'pretty_term' => 'Zombified Piglin Spawn Egg', 'type' => 'item', 'unit_type' => 'amount', ], ]
从服务器获取玩家列表
use Josantonius\MinecraftServerPlayerStat\MinecraftServer; $minecraftServer = new MinecraftServer( version: '1.17', language: 'en_us', logsPath: '/minecraft/logs', statsPath: '/minecraft/saves/world/stats', storagePath: '/data/storage', ); $players = $minecraftServer->getPlayerList();
$players
[ /* ... */ 'armadillo' => '14e55460-c753-31f2-bd0a-c305e2ff34b5', 'aguilar11235813' => '18f154fe-3678-37e9-9b77-185e0bfe446d', 'krakenbite' => '5cd5d2e7-9b3a-3f06-befb-34f7a81b14c6', 'tweedlex' => '8cb86072-3472-3b86-90f2-1e11b7188197', 'spook' => '8d5b923d-37fb-38d1-8a6a-a17cd5ccf768', ]
测试
git clone https://github.com/josantonius/php-minecraft-server-player-stat.git
cd PHP-MimeType
composer install
使用 PHPUnit 运行单元测试
composer phpunit
使用 PHPCS 运行代码规范测试
composer phpcs
运行 PHP Mess Detector 测试以检测代码风格的冲突
composer phpmd
运行所有之前的测试
composer tests
待办事项
- 添加新功能
- 改进测试
- 改进文档
- 改进README文件中的英文翻译
- 重构代码以禁用代码风格规则(参见 phpmd.xml 和 phpcs.xml)
变更日志
每个版本的详细更改记录在 发行说明 中。
贡献
在提交拉取请求、开始讨论或报告问题之前,请务必阅读 贡献指南。
感谢所有 贡献者! ❤️
赞助
如果此项目帮助您减少了开发时间,您可以 赞助我 以支持我的开源工作 😊
许可
此存储库受 MIT 许可证 的许可。
版权 © 2021-2023,Josantonius