Skip to content

Scoreboard API

MattMX edited this page Jul 4, 2024 · 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 dynamic scoreboard

Currently only available on dev branch!

val scoreboard = dynamicScoreboard(!"&dYour Title") {

    var t = false
    val line = scoreboardLine {
        t = !t
        !"${if (t) "&c" else "&7"}&m                      "
    }

    +line
    +!"&fStatic line"
    +{ !"&fServer Time: ${Date()}" } updateEvery 20L // every 1s
    +line
}

If you wish to update manually you can also call scoreboard[index] = !"Some other component" which will update for all players live.

You can also update the title dynamically.

val titleChanger = dynamicScoreboard {
    var counter = 0
    title { !"&fTitle component ${counter++}" } updateEvery 20L 
}

Furthermore you can use signals inside the DynamicScoreboardBuilder.

var counter by signal(0)

val counterDisplay = dynamicScoreboard(!"Times ran") {
    +{ !"&fYou've done this &a$counter &ftimes." }
}

("inc-counter").runs<Player> {
    if (!counterDisplay.isShownFor(sender)) {
        counterDisplay.showFor(sender)
    }

    reply(!"&fCounter is now ${counter++}.")
}
Clone this wiki locally