Scoreboard (Not API)

May 24, 2018 at 4:09 PM
Scoreboard (Not API)
  • BungeeCord Scoreboard (Not API)

    How to use BungeeCord to create a scoreboard



    @md_5 & @Thinkofdeath created the Bungeecord Scoreboard API (net.md_5.bungee.api.score.*) a long time ago. But it isn't ready to use yet. Nevertheless they already made the packets. So we can use them to create scoreboards! In the following code examples p stands for some ProxiedPlayer.


    How do scoreboards work?(top)

    Very important for creating a scoreboard via Bungeecord is to understand how scoreboards work. The best way to figure that out is by taking a look at the scoreboard objective packet on the Protocol page on wiki.vg.

    Creating an objective(top)

    So now we know how scoreboards work. First we have to create an objective.
    Code (Text):
    ScoreboardObjective objective = new ScoreboardObjective("test", "Test", "integer", (byte) 0);
    p.unsafe().sendPacket(objective);
    Explanation:
    "test" is an unique name for the scoreboard
    "Test" is the name which should be displayed
    "integer" this could be replaced to "hearts" - more infos
    0 - 0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.

    Creating and removing a score(top)

    Code (Text):
    ScoreboardScore score = new ScoreboardScore("Hallo", (byte) 0, "test", 0);
    p.unsafe().sendPacket(score);
    Explanation:
    "Hallo" is the name of the score to be updated or removed
    0 - 0 to create/update an item. 1 to remove an item.
    "test" is the name of the objective the score belongs to
    0 - The score to be displayed next to the entry.

    Displaying the scoreboard(top)

    Now the client knows all about the scorebaord, but we have to tell the client to display the scoreboard.
    Code (Text):
    ScoreboardDisplay display = new ScoreboardDisplay((byte) 1, "test");
    p.unsafe().sendPacket(display);
    Explanation:
    1 - The position of the scoreboard. 0: list, 1: sidebar, 2: below name.
    "test" - The unique name for the scoreboard to be displayed.

    And that's it. It is obviously very simple. And if you did everything right it should look like this:
    [​IMG]

    Note(top)

    The Client will only accept these packets if they are ingame. That means that if you want to send a scoreboard to some player when they join, you can at the earliest send it to them during the ServerSwitchEvent (which also gets send the first time you join a server). All earlier events (like PostLogin or ServerConnected) are posted before the Client is ready.
  • Loading...
  • Loading...