Skip to content

Scoreboard API

MattMX edited this page Oct 27, 2022 · 8 revisions

Creating a static scoreboard

Start off by calling scoreboard(title)

val scoreboard = scoreboard("Title")

This will create a usable scoreboard with the title of Title.

Remember that titles can only be up to 16 chars long

Adding lines

val scoreboard = scoreboard("Title") {
    add("This is a line")
    // Skips a line (hence whitespace)
    whitespace()
    add("This is another line")
}

Remember that scoreboards can only have 16 lines

You can then display the scoreboard to a player like so.

player.scoreboard  = scoreboard.scoreboard()

Creating an animated scoreboard

Very similar to the static scoreboard, do the following.

We also need to add another argument, which will depict how often the scoreboard should be updated. This argument should be provided in ticks.

val scoreboard = animatedScoreboard("Title", 10)

We add lines like normal in the static method.

Animating the scoreboard

We decide what animations we want in the update call.

val scoreboard = animatedScoreboard("Title", 10) {
    add("This is a line")
    whitespace()
    add("This is another line")
}.update {
    val text = "This is a line"
    // Calculate the amount of characters we should display
    // We can call getIterations() to see how many times we've iterated.
    val chars = min((getIterations() % text.length).toInt(), text.length)
    // Update the scoreboard with the new text
    set(0, text.substring(chars))
}

The scoreboard will not yet animate, we need to call .begin(plugin)

Calling this will begin an async repeating task with a delay of what we provided in the animatedScoreboard call.

We can always cancel this with the scoreboard.cancel() call.

Final animated scoreboard

val scoreboard = animatedScoreboard("Title", 10) {
    add("This is a line")
    whitespace()
    add("This is another line")
}.update {
    val text = "This is a line"
    // Calculate the amount of characters we should display
    // We can call getIterations() to see how many times we've iterated.
    val chars = min((getIterations() % text.length).toInt(), text.length)
    // Update the scoreboard with the new text
    set(0, text.substring(chars))
}.begin(plugin)

player.scoreboard = scoreboard.scoreboard()
Clone this wiki locally