valiant-bedrock / libscoreboard
为 PocketMine-MP 编写的轻量级记分板库
0.5.0
2022-05-20 00:27 UTC
Requires (Dev)
- pocketmine/bedrock-protocol: >=9.0.0+bedrock-1.18.30
- pocketmine/pocketmine-mp: >=4.3.0
This package is auto-updated.
Last update: 2024-09-16 05:19:36 UTC
README
为 Minecraft: 基岩版编写的轻量级记分板库
安装
Composer
运行以下命令以安装此包:composer require valiant-bedrock/libscoreboard
病毒
此项目的病毒位于此处,并可以从此处安装
枚举类型
此库提供两种枚举类型,用于发送记分板
DisplaySlot
- 用于指定记分板应显示的位置SortOrder
- 用于对记分板进行排序(升序或降序)
方法
管理视图
send(?SortOrder $sortOrder = null, ?DisplaySlot $displaySlot = null): void
- 向玩家发送记分板remove(): void
- 从客户端视图中移除记分板update(): void
- 强制更新客户端的记分板(如果记分板尚未可见,则抛出异常)
设置数据
此库提供多种方法用于更新记分板
setLines(array $lines, bool $clear = true, bool $update = true): void
- 设置所有行的值setLine(int $index, string $value, bool $update = true): void
- 设置特定行的值removeLine(int $index, bool $update = true): void
- 移除特定行clear(bool $update = true): void
- 清除记分板setDisplaySlot(DisplaySlot $slot, bool $update = true): void
- 设置记分板的显示槽setSortOrder(SortOrder $order, bool $update = true): void
- 设置记分板的排序顺序
示例
assert($player instanceof Player); $scoreboard = new Scoreboard( player: $player, title: "Test Scoreboard", lines: [ 0 => "Name: {$player->getName()}", 1 => "", 2 => "Test Entry", 3 => "", 4 => "Test Entry 2", ] ); // Sends the scoreboard to the player $scoreboard->send( slot: DisplaySlot::SIDEBAR(), order: SortOrder::ASCENDING() ); // Sets the line and sends it to the player (if visible) $scoreboard->setLine(index: 2, value: "New Text Entry"); // Set multiple lines $scoreboard->setLines( lines: [ 0 => "Display Name: {$player->getDisplayName()}", 1 => "Health: " . (string) round($player->getHealth(), 2), 2 => "", 3 => "Updated Test Entry", ], // If clear is set to true, it'll clear the scoreboard before setting the lines clear: true ); // Remove a line $scoreboard->removeLine(index: 2); // Changes the current sort order $scoreboard->setSortOrder(SortOrder::DESCENDING()); // Removes the scoreboard from the player's view $scoreboard->remove();
问题
关于此库的问题/建议可以在此处报告。