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 is
- Set up the project
- addon.yml
- The main class
- Lifecycle
- What plugin gives you
- Config and message files
- What you can register
- Commands
- Admin commands
- Permissions
- Menu functions
- Menus
- Placeholders
- Requirement types
- Island bonuses
- Where /is takes players
- Editor page
- Listeners and tasks
- Island helper, bank and levels
- Leaderboards
- Store data per island
- Sell things safely
- Island rights
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.
- Publish the ALBCore API jar to your local Maven repository, as described in Build a plugin.
- Copy the ALBSkyblock jar your server runs into your project's
libs/folder. - Create
build.gradle.ktsandgradle.propertiesas below.
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")
}kotlin.stdlib.default.dependency=falseThe project looks like this:
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.ymlBuild 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.
id: motto
name: Island Motto
main: com.example.motto.MottoAddon
version: '${version}'
description: A motto for your island (/is motto)
authors: [You]
depends: []| Key | Needed | What it is |
|---|---|---|
id | yes | a-z, 0-9, _ and -, up to 32 characters. It is also the addon's folder: plugins/ALBSkyblock/addons/<id>/. |
name | no | The name in the console and in /is admin editor > Addons. Default: the id. |
main | yes | The full name of your main class. It must extend SkyblockAddon and have a constructor without arguments. |
version | no | Shown in the console and the editor. Default: ?. |
description | no | One line, shown in /is admin editor > Addons. |
authors | no | A list of names. |
depends | no | Ids of other addons that must be loaded first. |
How addons load:
- Jars are read in file name order. An addon in
dependsis 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 reloaddoes 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:
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:
# Island Motto addon. Edit, then run /is admin reload.
# Longest motto players may set.
max-length: 32# Island Motto messages. Also editable in game: /is admin editor > Messages.
motto:
help: "Set your island's motto (no text removes it)"
set: "{prefix}ADE80✔ &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}ADE80✔ &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
| Method | When it runs | What 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
| Field | What it is |
|---|---|
plugin.lang | Messages (ALBCore's Lang): send(sender, key, "name" to value), raw(key, ...), lines(key, ...). |
plugin.teams | Who is on which island: islandOf(player), role(island, uuid), isTeam, isTrusted, isBanned, can(player, island, right), teamSize(islandId), name(uuid). |
plugin.islands | Islands: at(location), island(id), allIslands(), ownedBy(uuid). |
plugin.flags | Small values per island. See Store data per island. |
plugin.payments | Safe purchases. See Sell things safely. |
plugin.economy | Vault money: isEnabled(), balance, has, withdraw, deposit, format. |
plugin.addons | The other addons: isInstalled(id), unmet(...), bonus(...), withBonus(...), leaderboardRanks(). |
plugin.bank, plugin.levels, plugin.helpers | The 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.
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 nullconfig(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.listsnames 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 inonReload, so hand edits and/is admin reloadwork.
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, likemotto:. - Your sections show in
/is admin editor> Messages. lang-versionworks the same as in ALBCore.
What you can registerLink to this section
| Method | What it adds |
|---|---|
registerCommand | A /is <name> subcommand. |
registerAdminCommand | An /is admin <name> subcommand. |
registerPermission | A permission node. |
registerFunction | A [function] <id> that any menu button can run. |
registerMenu | A menu file the admin can edit in game. |
registerPlaceholders | {placeholders} for island menus. |
registerRequirement | A requirement type like level:10 for configs. |
registerBonus | Raises island values (size, team, homes...). |
registerSpawnProvider | Where /is takes players on an island. |
registerEditor | A page in /is admin editor > Addons. |
registerListener, track | Bukkit listeners and scheduler tasks. |
registerHelper, registerBank, registerLevels | The island helper, bank or levels. One of each per server. |
registerLeaderboard, registerLeaderboardRanks | A board for /is top, or the /is top ranks themselves. |
CommandsLink to this section
context.registerCommand(AddonCommand("motto", "albskyblock.command.motto", plugin.lang.raw("motto.help")) { player, args ->
setMotto(player, args.joinToString(" "))
})AddonCommand | What it is |
|---|---|
name | The subcommand: /is motto. |
permission | Needed 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. |
help | The line in /is help. "" keeps it out of the help. |
run | Gets the player and the words after the command. |
- Only players can use
/issubcommands. The console gets a message instead. - Register commands in
onEnable./isis 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.
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 ?: "?"))
}
}
})AddonAdminCommand | What it is |
|---|---|
name | The subcommand: /is admin motto. |
usage | Its arguments, shown in /is help: <clear> <player>. |
help | What it does, shown in /is help. |
build | Arguments, subcommands and actions, with ALBCore's CommandBuilder. |
PermissionsLink to this section
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.
Menu functionsLink to this section
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.
context.registerFunction(AddonFunction("open-motto", Material.NAME_TAG, "DD3FCOpen island motto",
permission = PERMISSION) { player, back ->
openMenu(player, back)
})AddonFunction | What it is |
|---|---|
id | What menus write: [function] open-motto. |
icon | Its icon in the editor's function picker. |
label | Its name in the function picker (colour codes work). |
menu | The only menu whose editor offers it. null (the default) offers it in every menu. |
permission | Needed to click it. Players without it get the "no permission" message. "" (the default) means everyone. Normally the same as your command's permission. |
run | Gets 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.
MenusLink to this section
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.
# 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: "DD3FC&lIsland motto"
lore:
- "&7{motto}"
- ""
- "DD3FC» &fClick &7to remove it."
actions:
- "[function] motto-clear"
back:
slot: 22
item: ARROW
name: "DD3FC← Back"
actions:
- "[back]"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, "DD3FCRemove 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,MenuContextandFunctionImplare incom.aayan.albskyblock.menu.FlagMenusis incom.aayan.albskyblock. MenuContextalso takespage,entries(the list area),titleandhead. 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
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. islandis 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:
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:
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",
))Requirement | What it is |
|---|---|
type | The word before the colon. Case does not matter. |
met | True when the player (and their island, or null) meets the value. |
describe | How players read it: "3 team members". |
progress | Optional. Shown after it: "(you: 1)". |
icon, example | Optional. 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:
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.
context.registerBonus(IslandBonus { island, key ->
when (key) {
"homes" -> if (isEventIsland(island)) 10 else null // at least 10 homes
else -> null // no opinion
}
})| Key | Read by | Value |
|---|---|---|
size | ALBSkyblock | Island size (blocks per side). |
team, trusted | ALBSkyblock | Team and trusted player limits. |
homes | Homes | Home limit. |
generator | Generators | Highest unlocked generator tier. |
generator-speed | Generators | Chance in percent that a mined generator block comes back at once. |
limit.<block> | Block Limits | A block limit, like limit.hopper. |
entity.<key> | Block Limits | A mob limit, like entity.villager or entity.mobs. |
bank | Island Bank | Bank capacity (money). |
storage | Island Storage | Storage 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.
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
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:
fun set(path: String, value: Any?) {
yml.set(path, value)
context.saveConfig(yml)
loadConfig()
}Listeners and tasksLink to this section
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:
| Register | Read it with | The official one |
|---|---|---|
registerHelper(IslandHelper) | plugin.helpers | Island Helper |
registerBank(IslandBank) | plugin.bank | Island Bank |
registerLevels(IslandLevels) | plugin.levels | Level |
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:
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.
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 */ }
}HelperEntrance | How the helper shows up |
|---|---|
NONE | It is just there (someone walked onto the island). |
SPAWN | It pops in (it moved to a new spot). |
LAND | It 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.
context.registerLeaderboard(LeaderboardSource(
id = "mottos",
name = "DD3FCLongest 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" },
))LeaderboardSource | What it is |
|---|---|
id | a-z, 0-9 and -. Used in placeholders. |
name | The board's name (colour codes work). |
icon | Its button in the /is top hub. |
description | One line on its button. |
order | Its place in the hub. Lower comes first. |
score | The island's score. Higher ranks first. Return null to leave the island off this board. |
display | What a board line shows for an island and its score. |
scoreruns 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>andtop-<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
idinonReload. It replaces the old one.
To show an island's place on any board (like the Level addon's {rank}), read the live ranks:
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 ithas(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.
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 withperm.orsetting.(island rights and settings) or keys of the official addons. - The new value counts at once, even before it is saved.
savecompletes 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
IslandResetEventlistener.
For lists or a lot of data, give your addon its own tables with ALBCore's migrations. Run them at the start of onEnable:
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:
- Only one purchase runs per island at a time. A double click, a team mate or lag gets
BUSY. - 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.
- It then runs your
applyon the main thread.applychecks the purchase is still valid, saves it, and completes with true only once it is saved. - If
applyreturns false, throws or fails to save, the money and items go back.
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, island | Who buys, and for which island. |
cost | The money (0 means no money). |
payer | Payer.PLAYER (their Vault money) or Payer.BANK (the island bank). |
reason | Shown in the bank history and the logs, like "Upgrade: Island Size II". |
items | Optional. Items taken from the player's inventory, as Map<ItemRef, Int> (vanilla or Nexo). See ALBCore's ItemRef. |
apply | Saves the purchase. Completes with true only once it is saved. |
The returned future completes on the main thread with a PaymentResult:
| Result | Meaning |
|---|---|
DONE | Paid and saved. |
BUSY | Another purchase of this island is running. Nothing was taken. |
NO_ECONOMY | The player pays, but there is no Vault economy. Nothing was taken. |
NO_BANK | The bank pays, but no bank addon is installed. Nothing was taken. |
NOT_ENOUGH | Not enough money, or the bank was busy. Nothing was taken. |
CANCELLED | A listener of IslandPrePurchaseEvent stopped it. Nothing was taken. |
MISSING_ITEMS | The player does not carry the items. Nothing was taken. |
FAILED | Paid, but apply failed. Money and items were given back. |
REFUND_FAILED | Like 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'slang.yml(payments.*).result.nothingTakenis true for every result exceptDONE,FAILEDandREFUND_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
IslandPrePurchaseEventbefore andIslandPurchaseEventafter. 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.
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.