galaxygames/libscoreboard 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

galaxygames/libscoreboard

最新稳定版本:1.0.7

Composer 安装命令:

composer require galaxygames/libscoreboard

包简介

libscoreboard

README 文档

README

libscoreboard

documents

1. General

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

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

1.1 Create scoreboard

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

1.2 Remove scoreboard

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

1.3 Change display name

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

2. Lines

Important These following instructions won't immediately show the changed line to player, they are required to send this code after the changes as the requirement to get it shown to player!

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

2.1 Set scoreboard line

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

Example:

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

but the scoreboard won't have lines between 0 and 4... that is why floodLine existed!

/** @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);

Example:

$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 Remove a line

/** @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);

Example:

$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 Fluent code style

$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 Make Unique

Important (REMOVED!), All lines are made unique by default.

Redundant

Because each lines must have a unique context, if you put a set of two lines with the same context it will fail... To solve this, use 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. Other functions

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

统计信息

  • 总下载量: 27
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2023-08-20