galaxygames/libscoreboard

libscoreboard

1.0.7 2023-09-24 18:37 UTC

This package is not auto-updated.

Last update: 2024-09-29 18:07:18 UTC


README

libscoreboard

文档

1. 通用

use galaxygames\scoreboard\Scoreboard;
...
class EgPlugin extends PluginBase{
  protected Scoreboard $scoreboard;

  public function onEnable() : void{
    $this->scoreboard = Scoreboard::getInstance();
  }
}

1.1 创建计分板

/**
 * @var Player $player
 * @var string $objectiveName
 * @var string $displayName
 */
$this->scoreboard->create($player, $objectiveName, $displayName)

1.2 移除计分板

$this->scoreboard->remove($player)

1.3 修改显示名称

/** @var string $newDisplayName */
$this->scoreboard->setDisplayName($player, $newDisplayName);

2. 行

重要 以下说明不会立即显示给玩家改变的行,必须在更改后发送此代码才能满足显示给玩家的需求!

$this->scoreboard->update($player)

2.1 设置计分板行

/** @var int $line Line number, range from 0 to 15*/
/** @var string $context Context of the line*/
$this->scoreboard->setLine($player, $line, $context);

示例

$this->scoreboard->setLine($player, 0, "line 1");
$this->scoreboard->setLine($player, 4, "line 4");

但是计分板不会在0到4之间有行...这就是为什么有floodLine的原因!

/** @var int $start The start line which it will flood, default: 0*/
/** @var int $end The end line where the flood end, default: 15*/
/** @var string $flood The line in the range will be flooded by this value, default: ""*/
$this->scoreboard->floodLine($player, $start, $end, $flood);

示例

$this->scoreboard->floodLine($player, 0, 3, "hello"); // Flood from line 0 to line 3 with "hello"
$this->scoreboard->floodLine($player, 4, 14); // Flood from line 4 to line 14 with empty line

2.2 移除一行

/** @var bool $brutal The removal will remove the line without putting an empty line if
this is true, default: fault */
$this->scoreboard->removeLine($player, $line, $brutal);

示例

$this->scoreboard->removeLine($player, 1); //Remove line 1 and leave behind an empty line
$this->scoreboard->removeLine($player, 0); //Remove line 0 without leave behind an empty line

2.3 流畅的代码风格

$this->scoreboard->create($player, "board", "My board")
    ->setLine($player, 0, "line 0")
    ->floodLine($player, 1, 12)
    ->setLine($player, 13, "line 13")
    ->removeLine($player, 9)
    ->update($player);

2.4 使其唯一

重要 (已移除!),默认情况下所有行都是唯一的。

冗余

因为每行必须有唯一的上下文,如果您放置具有相同上下文的两组行,它将失败...为了解决这个问题,请使用 Scoreboard::makeUnique

$this->scoreboard->create($player, "board", "My board")
    ->setLine($player, 0, Scoreboard::makeUnique(0, "unique"))
    ->setLine($player, 1, Scoreboard::makeUnique(0, "unique"))
    ->setLine($player, 2, Scoreboard::makeUnique(0, ""))
    ->setLine($player, 3, Scoreboard::makeUnique(0, ""));

image -> image

3. 其他功能

Scoreboard::getObjectiveName(Player $player); // Return the current color's name of a player
Scoreboard::clearPlayerCache(Player $player); // This should be called when player left the server
Scoreboard::clearCache(); // Clear all data