PHP code example of valiant-bedrock / libscoreboard

1. Go to this page and download the library: Download valiant-bedrock/libscoreboard library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

valiant-bedrock / libscoreboard example snippets


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();