ALB Studio

Addon API

Write your own ALBSkyblock addon: project setup, addon.yml, the addon lifecycle, everything an addon can register, island data and safe purchases.

Docs updated · What changed

On this page

What an addon isLink to this section

An addon adds a feature to /is: a subcommand, a menu, menu buttons, placeholders, a settings page in the editor, and so on. All the official addons (bank, levels, upgrades...) are built this way, and you can write your own with the same API.

An addon is a jar with an addon.yml inside. Server owners drop it into plugins/ALBSkyblock/addons/. ALBSkyblock loads it when the server starts, not Paper. Everything an addon registers is removed again when it is disabled.

This page builds a small example addon, Island Motto: /is motto <text> sets a motto for the island, and visitors see it when they arrive.

Set up the projectLink to this section

An addon compiles against ALBSkyblock, ALBCore, Paper and Kotlin. All four are already on the server, so they are compileOnly and never go into your jar.

  1. Publish the ALBCore API jar to your local Maven repository, as described in Build a plugin.
  2. Copy the ALBSkyblock jar your server runs into your project's libs/ folder.
  3. Create build.gradle.kts and gradle.properties as below.
build.gradle.kts
plugins {
    kotlin("jvm") version "2.4.21"
}

group = "com.example"
version = "1.0.0"

repositories {
    mavenLocal()
    mavenCentral()
    maven("https://repo.papermc.io/repository/maven-public/")
}

dependencies {
    // Everything an addon uses is already on the server: never bundle any of it.
    compileOnly(files("libs/ALBSkyblock.jar"))
    compileOnly("io.papermc.paper:paper-api:26.3.build.252-stable")
    compileOnly("com.aayan:alb-core:1.5.0")
    compileOnly(kotlin("stdlib"))
}

kotlin {
    jvmToolchain(25)
}

// Writes the project version into addon.yml.
tasks.processResources {
    val props = mapOf("version" to project.version)
    inputs.properties(props)
    filteringCharset = "UTF-8"
    filesMatching("addon.yml") { expand(props) }
}

tasks.jar {
    archiveFileName.set("ALBSkyblock-Motto.jar")
}
gradle.properties
kotlin.stdlib.default.dependency=false

The project looks like this:

text
island-motto/
├── build.gradle.kts
├── gradle.properties
├── libs/
│   └── ALBSkyblock.jar
└── src/main/
    ├── kotlin/com/example/motto/MottoAddon.kt
    └── resources/
        ├── addon.yml
        ├── config.yml
        ├── lang.yml
        └── menus/
            └── motto.yml

Build it with ./gradlew build. The jar is in build/libs/. Install it like any addon: see Install an addon.

addon.ymlLink to this section

Every addon jar has an addon.yml at its root.

src/main/resources/addon.yml
id: motto
name: Island Motto
main: com.example.motto.MottoAddon
version: '${version}'
description: A motto for your island (/is motto)
authors: [You]
depends: []
KeyNeededWhat it is
idyesa-z, 0-9, _ and -, up to 32 characters. It is also the addon's folder: plugins/ALBSkyblock/addons/<id>/.
namenoThe name in the console and in /is admin editor > Addons. Default: the id.
mainyesThe full name of your main class. It must extend SkyblockAddon and have a constructor without arguments.
versionnoShown in the console and the editor. Default: ?.
descriptionnoOne line, shown in /is admin editor > Addons.
authorsnoA list of names.
dependsnoIds of other addons that must be loaded first.

How addons load:

  • Jars are read in file name order. An addon in depends is always started before the addons that need it.
  • If an addon it depends on is not installed (or failed), the addon is skipped and the console says why.
  • If two jars have the same id, the second one is skipped.
  • Addons are only loaded when the server starts. /is admin reload does not load new jars.

The main classLink to this section

Your main class extends SkyblockAddon. It gets two things:

  • context: your addon's handle on ALBSkyblock. You register everything through it.
  • plugin: the running ALBSkyblock plugin, with its islands, teams, messages and more.

Here is the whole Island Motto addon:

src/main/kotlin/com/example/motto/MottoAddon.kt
package com.example.motto

import com.aayan.albskyblock.api.AddonCommand
import com.aayan.albskyblock.api.PlaceholderProvider
import com.aayan.albskyblock.api.SkyblockAddon
import com.aayan.albskyblock.api.event.IslandEnterEvent
import com.aayan.albskyblock.island.Island
import com.aayan.albskyblock.island.IslandPermission
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener

class MottoAddon : SkyblockAddon(), Listener {

    private var maxLength = 32

    override fun onEnable() {
        loadConfig()
        context.registerMessages()
        context.registerCommand(AddonCommand("motto", PERMISSION, plugin.lang.raw("motto.help")) { player, args ->
            setMotto(player, args.joinToString(" ").trim())
        })
        context.registerPlaceholders(PlaceholderProvider { _, island ->
            listOf("motto" to (island?.let { mottoOf(it) } ?: ""))
        })
        context.registerListener(this)
    }

    override fun onReload() {
        loadConfig()
    }

    private fun loadConfig() {
        maxLength = context.config().getInt("max-length", 32)
    }

    fun mottoOf(island: Island): String = plugin.flags.raw(island.id, FLAG).orEmpty()

    private fun setMotto(player: Player, text: String) {
        val lang = plugin.lang
        val island = plugin.teams.islandOf(player) ?: return lang.send(player, "island.none")
        // Only roles with the Settings right (and the owner) may change it.
        if (!plugin.teams.can(player, island, IslandPermission.SETTINGS)) {
            return lang.send(player, "team.no-right", "action" to lang.raw("permissions.settings"))
        }
        if (text.length > maxLength) return lang.send(player, "motto.too-long", "max" to maxLength)
        plugin.flags.set(island.id, FLAG, text)
        lang.send(player, if (text.isEmpty()) "motto.cleared" else "motto.set")
    }

    // Visitors see the motto under the arrival title.
    @EventHandler
    fun onEnter(event: IslandEnterEvent) {
        val motto = mottoOf(event.island)
        if (motto.isNotEmpty()) event.subtitle = plugin.lang.raw("motto.subtitle", "motto" to motto)
    }

    companion object {
        const val PERMISSION = "albskyblock.command.motto"
        const val FLAG = "motto.text"
    }
}

And its default files:

src/main/resources/config.yml
# Island Motto addon. Edit, then run /is admin reload.

# Longest motto players may set.
max-length: 32
src/main/resources/lang.yml
# Island Motto messages. Also editable in game: /is admin editor > Messages.
motto:
  help: "Set your island's motto (no text removes it)"
  set: "{prefix}&#4ADE80✔ &7Island motto set."
  cleared: "{prefix}&7Island motto removed."
  too-long: "{prefix}&#F87171✖ &7A motto can be up to {max} characters."
  subtitle: "&7“{motto}”"
  colors-bought: "{prefix}&#4ADE80✔ &7Motto colours unlocked."
motto-admin:
  no-island: "{prefix}&#F87171✖ &7That player has no island."
  cleared: "{prefix}&7Removed the motto of {player}'s island."

LifecycleLink to this section

MethodWhen it runsWhat to do there
onEnable()When the server starts: after ALBSkyblock's own start, before /is is registered.Read your config and register everything.
onReload()On /is admin reload, after ALBSkyblock re-read its own files.Read your files again.
onDisable()When the server stops.Save your data and stop what you started yourself.

Commands, menus, listeners, tracked tasks and everything else you registered are removed by ALBSkyblock. You don't undo them in onDisable.

If onEnable throws, the console shows the error, everything the addon registered so far is removed, and the addon is not loaded. The other addons keep working.

What plugin gives youLink to this section

FieldWhat it is
plugin.langMessages (ALBCore's Lang): send(sender, key, "name" to value), raw(key, ...), lines(key, ...).
plugin.teamsWho is on which island: islandOf(player), role(island, uuid), isTeam, isTrusted, isBanned, can(player, island, right), teamSize(islandId), name(uuid).
plugin.islandsIslands: at(location), island(id), allIslands(), ownedBy(uuid).
plugin.flagsSmall values per island. See Store data per island.
plugin.paymentsSafe purchases. See Sell things safely.
plugin.economyVault money: isEnabled(), balance, has, withdraw, deposit, format.
plugin.addonsThe other addons: isInstalled(id), unmet(...), bonus(...), withBonus(...), leaderboardRanks().
plugin.bank, plugin.levels, plugin.helpersThe island bank, island levels and island helper. Null when no addon provides them.
plugin.bypass(player)True when the player is staff with bypass on.

Call all of these from the main thread.

Config and message filesLink to this section

Your addon's files live in its own folder, plugins/ALBSkyblock/addons/<id>/ (context.dataFolder). The defaults come from your jar.

Kotlin
val yml = context.config()                                 // addons/<id>/config.yml
val rewards = context.config("rewards.yml", lists = setOf("rewards"))
yml.set("max-length", 48)
context.saveConfig(yml)                                    // writes addons/<id>/config.yml
val defaults = context.resource("config.yml")              // the copy inside your jar, or null
  • config(name) copies the file from your jar the first time. Later, options you add in a new version are written into the server's file, with the comment header of your jar copy.
  • lists names sections that admins add to and delete from (rewards, block values...). Once the server's file has such a section, your default entries are not merged back in, so a deleted entry stays deleted.
  • Call config() again in onReload, so hand edits and /is admin reload work.

context.registerMessages() adds your lang.yml to ALBSkyblock's messages:

  • The file is addons/<id>/lang.yml, copied from your jar. New keys are added by themselves.
  • Your keys join ALBSkyblock's own, so plugin.lang.send(player, "motto.set") works, and so do {prefix} and the core keys (island.none, team.no-right...). Put your keys under a top-level section of your own, like motto:.
  • Your sections show in /is admin editor > Messages.
  • lang-version works the same as in ALBCore.

What you can registerLink to this section

MethodWhat it adds
registerCommandA /is <name> subcommand.
registerAdminCommandAn /is admin <name> subcommand.
registerPermissionA permission node.
registerFunctionA [function] <id> that any menu button can run.
registerMenuA menu file the admin can edit in game.
registerPlaceholders{placeholders} for island menus.
registerRequirementA requirement type like level:10 for configs.
registerBonusRaises island values (size, team, homes...).
registerSpawnProviderWhere /is takes players on an island.
registerEditorA page in /is admin editor > Addons.
registerListener, trackBukkit listeners and scheduler tasks.
registerHelper, registerBank, registerLevelsThe island helper, bank or levels. One of each per server.
registerLeaderboard, registerLeaderboardRanksA board for /is top, or the /is top ranks themselves.

CommandsLink to this section

Kotlin
context.registerCommand(AddonCommand("motto", "albskyblock.command.motto", plugin.lang.raw("motto.help")) { player, args ->
    setMotto(player, args.joinToString(" "))
})
AddonCommandWhat it is
nameThe subcommand: /is motto.
permissionNeeded to use it. ALBSkyblock registers it with default true, so everyone has it until an admin takes it away. Use albskyblock.command.<name>, like the official addons. "" means no permission check.
helpThe line in /is help. "" keeps it out of the help.
runGets the player and the words after the command.
  • Only players can use /is subcommands. The console gets a message instead.
  • Register commands in onEnable. /is is built once, after all addons have started, so a command registered later never shows up.
  • Pick a name that ALBSkyblock and the official addons don't use (tp, team, bank, home, top...). See Commands.

Admin commandsLink to this section

Admin commands are built with ALBCore's command builder. They need albskyblock.admin and also work from the console, so shops and crates can run them.

Kotlin
context.registerAdminCommand(AddonAdminCommand("motto", "<clear> <player>", "Remove the motto of a player's island") {
    subcommand("clear") {
        arg("player", ArgType.OFFLINE_PLAYER)
        action { sender, args ->
            val target = args.offlinePlayer("player")
            val island = plugin.teams.islandOf(target.uniqueId)
                ?: return@action plugin.lang.send(sender, "motto-admin.no-island")
            plugin.flags.set(island.id, FLAG, "")
            plugin.lang.send(sender, "motto-admin.cleared", "player" to (target.name ?: "?"))
        }
    }
})
AddonAdminCommandWhat it is
nameThe subcommand: /is admin motto.
usageIts arguments, shown in /is help: <clear> <player>.
helpWhat it does, shown in /is help.
buildArguments, subcommands and actions, with ALBCore's CommandBuilder.

PermissionsLink to this section

Kotlin
context.registerPermission("albskyblock.motto.colors", PermissionDefault.OP)

The node is added to the server and removed again when the addon stops. If a node with that name already exists, nothing changes. registerCommand and registerFunction don't need this: a command registers its own permission.

A function is code that a menu button runs with [function] <id>. Admins pick functions in the menu editor, so your feature can go into any menu.

Kotlin
context.registerFunction(AddonFunction("open-motto", Material.NAME_TAG, "&#7DD3FCOpen island motto",
    permission = PERMISSION) { player, back ->
    openMenu(player, back)
})
AddonFunctionWhat it is
idWhat menus write: [function] open-motto.
iconIts icon in the editor's function picker.
labelIts name in the function picker (colour codes work).
menuThe only menu whose editor offers it. null (the default) offers it in every menu.
permissionNeeded to click it. Players without it get the "no permission" message. "" (the default) means everyone. Normally the same as your command's permission.
runGets the player and back, which reopens the menu the click came from (null when there is none).

Some buttons need the state of the open menu, for example "delete this home". Register such a function with menu set to that menu and an empty run, so the editor offers it there. Then handle the click in MenuContext.functions when you open the menu (see below). The menu's own code is asked first.

A menu is a YAML file that admins can change in /is admin editor > Menus. You ship the default in your jar as menus/<menuId>.yml. It is copied to addons/<id>/menus/<menuId>.yml on the server.

src/main/resources/menus/motto.yml
# Island Motto addon: /is motto menu. Placeholders: {motto} + the island ones.
revision: 1
title: "&8ɪꜱʟᴀɴᴅ | ᴍᴏᴛᴛᴏ"
rows: 3
fill: edges
items:
  motto:
    slot: 13
    item: NAME_TAG
    name: "&#7DD3FC&lIsland motto"
    lore:
      - "&7{motto}"
      - ""
      - "&#7DD3FC» &fClick &7to remove it."
    actions:
      - "[function] motto-clear"
  back:
    slot: 22
    item: ARROW
    name: "&#7DD3FC← Back"
    actions:
      - "[back]"
Kotlin
private lateinit var menu: MenuDef

override fun onEnable() {
    // ...
    menu = context.registerMenu("motto") { player, back -> openMenu(player, back) }
    // Listed in the editor for this menu only; the click itself is handled in openMenu.
    context.registerFunction(AddonFunction("motto-clear", Material.BARRIER, "&#7DD3FCRemove the motto",
        menu = "motto", permission = PERMISSION) { _, _ -> })
}

fun openMenu(player: Player, back: ((Player) -> Unit)?) {
    val island = plugin.teams.islandOf(player) ?: return plugin.lang.send(player, "island.none")
    MenuView.open(plugin, player, menu, MenuContext(
        reopen = { p, _ -> openMenu(p, back) },
        back = back,
        // Island placeholders, including every addon's ({motto} too).
        placeholders = { viewer -> FlagMenus.islandPlaceholders(plugin, island, viewer) },
        functions = mapOf("motto-clear" to FunctionImpl(click = { p, _ ->
            setMotto(p, "")
            openMenu(p, back)
        })),
    ))
}
  • registerMenu(menuId) { player, back -> } returns the menu file (MenuDef). The function you give it runs when any menu uses [open] motto.
  • Open it with MenuView.open(plugin, player, def, MenuContext(...)). MenuDef, MenuView, MenuContext and FunctionImpl are in com.aayan.albskyblock.menu. FlagMenus is in com.aayan.albskyblock.
  • MenuContext also takes page, entries (the list area), title and head. See ALBCore's YAML menus.
  • Menu ids are shared with ALBSkyblock's menus and the other addons. Pick one that is not taken.
  • When you redesign a default menu, raise its revision. Servers keep their old copy as <menuId>.old.yml. See Menus and messages.

PlaceholdersLink to this section

Kotlin
context.registerPlaceholders(PlaceholderProvider { player, island ->
    listOf("motto" to (island?.let { mottoOf(it) } ?: ""))
})
  • The values work as {motto} in island menus: ALBSkyblock's own menus, your menus, and other addons' menus.
  • island is the viewer's island (owned or as a team member), or null when they have none.
  • Menus ask for the values every time they draw, so keep it cheap: read memory, not the database.

Addon placeholders are not PlaceholderAPI placeholders by themselves. Only ALBSkyblock's core keys, the official addons' keys and the /is top board keys are %albskyblock_<key>%. For your own, use ALBCore's PAPIHook with plugin as the owner:

Kotlin
PAPIHook.register(plugin, "motto", "text") { player ->
    plugin.teams.islandOf(player)?.let { mottoOf(it) } ?: ""
}   // %motto_text%

Requirement typesLink to this section

Configs gate things with requirements written as <type>:<value>, like level:10 or money:5000. See Requirements. An addon can add its own type:

Kotlin
context.registerRequirement(Requirement(
    type = "members",
    // An unreadable value is never met, so a typo can't open the gate for everyone.
    met = { _, island, value ->
        val need = value.toIntOrNull()
        island != null && need != null && plugin.teams.teamSize(island.id) >= need
    },
    describe = { value -> "$value team members" },
    progress = { _, island, _ -> "(you: ${island?.let { plugin.teams.teamSize(it.id) } ?: 0})" },
    icon = Material.PLAYER_HEAD,
    example = "3",
))
RequirementWhat it is
typeThe word before the colon. Case does not matter.
metTrue when the player (and their island, or null) meets the value.
describeHow players read it: "3 team members".
progressOptional. Shown after it: "(you: 1)".
icon, exampleOptional. The icon and an example value in the requirement editor.

ALBSkyblock itself registers money, item and placeholder. The official addons add level, bank and upgrade.

To check a list of requirements from your own config, use plugin.addons.unmet:

Kotlin
val missing = plugin.addons.unmet(player, island, yml.getStringList("requirements"))
missing.forEach { line -> MessageUtil.send(player, line) }   // "3 team members (you: 1)"

A type that no addon registered counts as met (the console says so once). That way a config can name a type before its addon is installed.

Island bonusesLink to this section

A bonus raises an island value: a bigger island, more team slots, more homes. The Upgrades addon uses this for everything it sells.

Kotlin
context.registerBonus(IslandBonus { island, key ->
    when (key) {
        "homes" -> if (isEventIsland(island)) 10 else null   // at least 10 homes
        else -> null                                           // no opinion
    }
})
KeyRead byValue
sizeALBSkyblockIsland size (blocks per side).
team, trustedALBSkyblockTeam and trusted player limits.
homesHomesHome limit.
generatorGeneratorsHighest unlocked generator tier.
generator-speedGeneratorsChance in percent that a mined generator block comes back at once.
limit.<block>Block LimitsA block limit, like limit.hopper.
entity.<key>Block LimitsA mob limit, like entity.villager or entity.mobs.
bankIsland BankBank capacity (money).
storageIsland StorageStorage slots.

To read a value with all bonuses applied: plugin.addons.withBonus(island, key, base). To read only the bonus: plugin.addons.bonus(island, key) (null when no addon answers).

Where /is takes playersLink to this section

/is normally takes players to the island spawn. A spawn provider can pick another spot. The Homes addon uses it for the main home.

Kotlin
context.registerSpawnProvider(SpawnProvider { island, world ->
    padOf(island)?.takeIf { island.insideBorder(it.blockX, it.blockZ) }   // null: no opinion
})

The first provider that returns a location wins. If none does, players go to the island spawn.

Editor pageLink to this section

Kotlin
context.registerEditor(EditorSection { player, back -> openSettings(player, back) })

Admins open it from /is admin editor > Addons > your addon. Build the page with ALBCore's GUI, and call back(player) to return to the addon list. Without an editor page, the addon list says your addon has no settings.

To change a setting from your page, set it, save the file and apply it:

Kotlin
fun set(path: String, value: Any?) {
    yml.set(path, value)
    context.saveConfig(yml)
    loadConfig()
}

Listeners and tasksLink to this section

Kotlin
context.registerListener(this)
context.track(plugin.server.scheduler.runTaskTimer(plugin, Runnable { tick() }, 20L, 20L))

An addon is not a Bukkit plugin, so listeners and tasks run under ALBSkyblock (plugin). Register listeners with registerListener and wrap tasks in track: they are unregistered and cancelled when the addon stops.

Island helper, bank and levelsLink to this section

Some features exist once per server. An addon provides one, and every other addon uses it:

RegisterRead it withThe official one
registerHelper(IslandHelper)plugin.helpersIsland Helper
registerBank(IslandBank)plugin.bankIsland Bank
registerLevels(IslandLevels)plugin.levelsLevel

If two addons register one, the last one wins. Don't provide one next to the official addon that does.

Most addons only use them. Each one is null when no addon provides it:

Kotlin
plugin.bank?.give(island, 250.0, null, "Motto contest prize")
plugin.levels?.takeIf { it.loaded }?.addBonusXp(island, 50, "Motto contest")

IslandBank and IslandLevels are described on the Skyblock API page.

To write your own island helper (an NPC on each island), implement IslandHelper. ALBSkyblock calls it at the moments only the core knows about: an island is created, reset or deleted, the intro starts or ends, someone joins the team. All calls come on the main thread.

Kotlin
class MyHelper : IslandHelper {
    override fun prepare(island: Island) { /* load or create the helper's spot ahead of time */ }
    override fun show(island: Island, entrance: HelperEntrance) { /* show it, if it is not shown yet */ }
    override fun hide(island: Island) { /* remove it from the world for now */ }
    override fun remove(island: Island) { /* island deleted or reset: remove it and forget its spot */ }
}
HelperEntranceHow the helper shows up
NONEIt is just there (someone walked onto the island).
SPAWNIt pops in (it moved to a new spot).
LANDIt arrives from the sky (after the intro, a skipped intro, /is create without intro, or a reset).

LeaderboardsLink to this section

With the Leaderboards addon installed, /is top shows every board that addons register. Without it, registering a board does nothing, so you can always register yours.

Kotlin
context.registerLeaderboard(LeaderboardSource(
    id = "mottos",
    name = "&#7DD3FCLongest Motto",
    icon = Material.NAME_TAG,
    description = "Ranked by motto length",
    order = 70,
    score = { island -> mottoOf(island).length.takeIf { it > 0 }?.toDouble() },
    display = { _, score -> "${score.toInt()} characters" },
))
LeaderboardSourceWhat it is
ida-z, 0-9 and -. Used in placeholders.
nameThe board's name (colour codes work).
iconIts button in the /is top hub.
descriptionOne line on its button.
orderIts place in the hub. Lower comes first.
scoreThe island's score. Higher ranks first. Return null to leave the island off this board.
displayWhat a board line shows for an island and its score.
  • score runs on the main thread for every island each time the boards are rebuilt. Keep it cheap: read memory, not the database.
  • Islands with the same score keep the order they were created in.
  • Islands that staff hid from the boards are left off for you.
  • Register the board in onEnable, so it gets its placeholders: rank-<id> and top-<id>-<n>-owner, -name, -value, -score (n is 1 to 10). See Placeholders.
  • To apply a changed name or description, register it again with the same id in onReload. It replaces the old one.

To show an island's place on any board (like the Level addon's {rank}), read the live ranks:

Kotlin
val ranks = plugin.addons.leaderboardRanks()                 // null without the Leaderboards addon
val rank = ranks?.takeIf { it.has("level") }?.rank("level", island.id)   // 1 = best, null = not on it

has(boardId) is true when the board is switched on and has been built. Both calls read the last rebuild, so they are cheap and safe on any thread. registerLeaderboardRanks is only for an addon that replaces the Leaderboards addon.

Store data per islandLink to this section

For a few small values per island, use island flags. They are text values, stored in ALBSkyblock's alb_skyblock_island_flags table. All of them are loaded at startup, so reading one is instant.

Kotlin
plugin.flags.raw(island.id, "motto.text")             // the island's value, or null
plugin.flags.set(island.id, "motto.text", "Hello")    // in memory now, saved in the background
plugin.flags.set(island.id, "motto.text", "")         // clear it
plugin.flags.save(island.id, "motto.text", "Hello")   // like set, and tells you if it was saved
    .thenAccept { saved -> /* false: the database refused it */ }
  • Start your keys with your addon id and a dot, like motto.text. Don't use keys starting with perm. or setting. (island rights and settings) or keys of the official addons.
  • The new value counts at once, even before it is saved. save completes with false (never with an error) when saving failed.
  • Open island menus redraw when a flag changes.
  • Flags are deleted with the island. A reset keeps them: if a value belongs to the old blocks, clear it in an IslandResetEvent listener.

For lists or a lot of data, give your addon its own tables with ALBCore's migrations. Run them at the start of onEnable:

Kotlin
ALBCore.instance.database.migrate("ALBSkyblock-Motto") {
    version(1, "Create motto history table") {
        execute("""CREATE TABLE ${table("skyblock_motto_history")} (
            island_id BIGINT NOT NULL,
            motto VARCHAR(64) NOT NULL,
            set_at BIGINT NOT NULL)""")
    }
}

Name your tables skyblock_<id>_..., so they sit next to the other addons' tables. When an island is deleted, drop its rows in an IslandDeletedEvent listener. See Events and Database.

Sell things safelyLink to this section

When your addon sells something (an upgrade, a perk, a tier), charge for it with plugin.payments.charge. It makes sure money is never lost and nothing is bought twice:

  1. Only one purchase runs per island at a time. A double click, a team mate or lag gets BUSY.
  2. It takes the money and the items first: from the player's wallet or the island bank, and items from the player's inventory. If that fails, it stops.
  3. It then runs your apply on the main thread. apply checks the purchase is still valid, saves it, and completes with true only once it is saved.
  4. If apply returns false, throws or fails to save, the money and items go back.
Kotlin
fun buyColors(player: Player, island: Island) {
    val cost = yml.getDouble("colors-cost", 5000.0)
    plugin.payments.charge(player, island, cost, Payer.PLAYER, "Motto colours") {
        // Runs after paying. Check again: the island may be gone, or someone bought it meanwhile.
        if (plugin.islands.island(island.id)?.state != IslandState.ACTIVE || hasColors(island)) {
            CompletableFuture.completedFuture(false)
        } else {
            plugin.flags.save(island.id, "motto.colors", "true").thenApply { saved ->
                // Not saved: take it away again (the payment is refunded for you).
                if (!saved) plugin.server.scheduler.runTask(plugin, Runnable { plugin.flags.set(island.id, "motto.colors", "") })
                saved
            }
        }
    }.thenAccept { result ->
        if (result == PaymentResult.DONE) plugin.lang.send(player, "motto.colors-bought")
        else plugin.payments.explain(player, result, cost)
    }
}
charge(...)What it is
player, islandWho buys, and for which island.
costThe money (0 means no money).
payerPayer.PLAYER (their Vault money) or Payer.BANK (the island bank).
reasonShown in the bank history and the logs, like "Upgrade: Island Size II".
itemsOptional. Items taken from the player's inventory, as Map<ItemRef, Int> (vanilla or Nexo). See ALBCore's ItemRef.
applySaves the purchase. Completes with true only once it is saved.

The returned future completes on the main thread with a PaymentResult:

ResultMeaning
DONEPaid and saved.
BUSYAnother purchase of this island is running. Nothing was taken.
NO_ECONOMYThe player pays, but there is no Vault economy. Nothing was taken.
NO_BANKThe bank pays, but no bank addon is installed. Nothing was taken.
NOT_ENOUGHNot enough money, or the bank was busy. Nothing was taken.
CANCELLEDA listener of IslandPrePurchaseEvent stopped it. Nothing was taken.
MISSING_ITEMSThe player does not carry the items. Nothing was taken.
FAILEDPaid, but apply failed. Money and items were given back.
REFUND_FAILEDLike FAILED, but giving back failed too. Staff are told in the console and the admin log.
  • plugin.payments.explain(player, result, cost) sends the matching message from ALBSkyblock's lang.yml (payments.*).
  • result.nothingTaken is true for every result except DONE, FAILED and REFUND_FAILED.
  • plugin.payments.isBusy(island) tells you a purchase is running, for example to grey out a button.
  • Items of a player who left during a purchase are given back on their next join.
  • Every purchase fires IslandPrePurchaseEvent before and IslandPurchaseEvent after. See Events.

Island rightsLink to this section

Island rights are what roles may do in /is permissions, like SETTINGS, GENERATOR or BANK_WITHDRAW. They are a fixed list in ALBSkyblock (IslandPermission); an addon checks them but can't add new ones.

Kotlin
if (!plugin.teams.can(player, island, IslandPermission.SETTINGS)) {
    return plugin.lang.send(player, "team.no-right", "action" to plugin.lang.raw("permissions.settings"))
}

can is always true for the island owner and for staff with bypass on. For "may this player build at this spot?", use SkyblockAPI.canBuild and its friends. The full list of rights is on the Skyblock API page.

Type a class, method, config key or topic. Use the arrow keys and Enter to open a result.