Skip to content

Scoreboard API

MattMX edited this page Nov 22, 2023 · 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.

Adding lines

val scoreboard = scoreboard(!"&a&lTitle") {
    add(!"&fThis is a line")
    add(!" ")
    add(!"&fThis is another line")
}

Remember that scoreboards can only have 16 lines

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

scoreboard.showFor(player)

Creating an animated scoreboard

Since KtGUI 2.0, we now expect you to animate your scoreboards yourself.

private int iterations = 0
fun update(scoreboard: Scoreboard) = scoreboard.apply {
    val text = "This is a line"

    // Calculate the amount of characters we should display
    val chars = min((iterations % text.length).toInt(), text.length)

    // Update the scoreboard with the new text
    this[0] = !"&f${text.substring(chars)}"
    iterations++
}

We can now call this method wherever we want, in an event or with a Scheduler.

You are not limited to inside of methods, you can change the scoreboard lines at any point in your plugins with Scoreboard#set(index, component).

Scoreboards also fully support RGB.

Clone this wiki locally