Developer API
Add your own placement rules, limits and access checks with the ALBMinions rule API and events.
Docs updated · What changed
On this page
What you can doLink to this section
Other plugins can work with minions through ALBMinionsAPI:
- Read placed minions: who owns them, where they are, their tier and what they store.
- Add rules: block placing somewhere, cap minions per area (like island slots), and let other players manage a minion.
- Remove minions, for example when a plot is cleared.
- Listen to events when a minion is placed, upgraded or removed.
The ALBSkyblock addon is built on this API.
Set up the projectLink to this section
The API is compileOnly: ALBMinions is already on the server, so it never goes into your jar. Publish the API jar to your local Maven repository first, by running ./gradlew publishToMavenLocal in the ALBMinions source folder.
repositories {
mavenLocal()
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
}
dependencies {
compileOnly("io.papermc.paper:paper-api:26.3.build.252-stable")
compileOnly("com.aayan:alb-minions:1.0.0")
compileOnly(kotlin("stdlib")) // ALBCore ships the Kotlin runtime: never shade it
}Add ALBMinions as a soft dependency, so it loads before your plugin:
softdepend: [ALBMinions]Without ALBMinions on the server, its classes can't be loaded. So check the plugin by name first, and keep every ALBMinions class in its own file that you only touch after that check:
class MyPlugin : JavaPlugin() {
val friends = Friends()
override fun onEnable() {
if (server.pluginManager.isPluginEnabled("ALBMinions")) MinionHooks.enable(this)
else logger.info("ALBMinions is not installed: no minion rules.")
}
}
// The only file that uses ALBMinions classes.
object MinionHooks {
fun enable(plugin: MyPlugin) {
ALBMinionsAPI.register(plugin, PlotMinionRule(plugin.friends))
plugin.server.pluginManager.registerEvents(MinionListener(plugin), plugin)
}
}ALBMinionsAPILink to this section
Every function is static, so Java calls it as ALBMinionsAPI.minions().
| Function | Returns |
|---|---|
isReady | true while ALBMinions is enabled. |
register(plugin, rule) | Adds a rule. It is removed by itself when your plugin disables. |
unregister(rule) | Removes one rule. |
unregisterAll(plugin) | Removes every rule of that plugin. |
rules() | The registered rules whose plugin is still enabled. |
minions() | Every placed minion. |
minion(id) | The minion with that id, or null. |
minionsOf(owner) | Every minion of one player (UUID). |
minionsIn(world, minX, minZ, maxX, maxZ) | Minions whose middle block is inside that box. The edges count. |
minionAt(location) | The minion whose work area covers that location, or null. The area is the 5x5 floor and the air above it. |
remove(minion, restoreFloor, giveItem) | Removes a minion. See Remove a minion. |
minions(), minion(), minionsOf(), minionsIn(), minionAt() and remove() throw an IllegalStateException while ALBMinions is not running. Check isReady when you are not sure.
MinionInfoLink to this section
The API gives every minion as a MinionInfo. It is read-only.
| Property | What it is |
|---|---|
id | The minion's id (Long). Players see it as #12 in the minion menu. |
owner | The owner's UUID. |
typeId | The type id from types.yml, like miner. |
tier | The tier, from 1. It changes when the minion is upgraded. |
worldName | The world's name. |
blockX, blockY, blockZ | The middle floor block. The minion stands on top of it. |
location | Where the minion stands, or null while its world is not loaded. |
covers(world, x, y, z) | true if the work area covers that block. |
storedItems() | Copies of the stored items. |
RulesLink to this section
A rule is a MinionRule. Every method has a default that means "no opinion", so you only write the ones you need.
| Method | Return | When it is asked |
|---|---|---|
checkPlace(player, typeId, center, area) | null to allow, or a message with colour codes that says why not. | A player places a minion. center is the clicked middle block, area the 25 floor blocks. |
limitAt(player, center) | An AreaLimit(placed, max, label), or null when there is no cap here. | A player places a minion. |
canManage(player, minion) | true to let the player use a minion they don't own, false to forbid it, null for no opinion. | A player opens a minion's menu, and on every click in it. |
onRemoved(minion, reason) | Nothing. | A minion was removed. |
When a placement is checkedLink to this section
- ALBMinions checks its own rules first: the world, the player's limit, overlap, the floor and WorldGuard.
- Then every rule, one after another: first
limitAt, thencheckPlace. The first "no" stops the placement. - Then
MinionPlaceEventfires. - Only then is the item taken and the minion placed.
Details:
- The message from
checkPlaceis sent to the player as it is. ALBMinions adds no prefix. - When
placedismaxor more, the player sees "Thislabelalready hasplaced/maxminions.", so pick alabellike"plot"or"island". - If
checkPlacethrows an exception, the placement is stopped. If one of the other methods throws, it counts as no opinion.
Who may use a minionLink to this section
The owner and players with albminions.admin.bypass may always use a minion. For anyone else, ALBMinions asks every rule's canManage:
- One
falsewins over everytrue. - With no
false, onetrueis enough. - With only
nullanswers, the player can't use it.
A player who may use a minion can open it, take items, upgrade it (and pays for it) and pick it up. The player who picks it up gets the minion item and its items.
Example ruleLink to this section
Plots are 100x100 blocks in the world plots. Each plot may hold 4 minions. Nobody may place a minion near the world spawn, and friends may look after each other's minions. Friends is your plugin's own class.
class PlotMinionRule(private val friends: Friends) : MinionRule {
override fun checkPlace(player: Player, typeId: String, center: Block, area: List<Block>): String? {
val spawn = center.world.spawnLocation
if (center.location.distanceSquared(spawn) < 100.0 * 100.0) return "&cNo minions within 100 blocks of spawn."
return null
}
override fun limitAt(player: Player, center: Block): AreaLimit? {
if (center.world.name != "plots") return null
val minX = Math.floorDiv(center.x, 100) * 100
val minZ = Math.floorDiv(center.z, 100) * 100
val placed = ALBMinionsAPI.minionsIn(center.world, minX, minZ, minX + 99, minZ + 99).size
return AreaLimit(placed, 4, "plot") // "This plot already has 4/4 minions."
}
override fun canManage(player: Player, minion: MinionInfo): Boolean? =
if (friends.areFriends(player.uniqueId, minion.owner)) true else null
override fun onRemoved(minion: MinionInfo, reason: RemoveReason) {
// Update your own plot data here.
}
}Remove a minionLink to this section
// In your plugin, on the main thread:
val minion = ALBMinionsAPI.minion(12) ?: return
ALBMinionsAPI.remove(minion, restoreFloor = true, giveItem = true).thenAccept { removed ->
if (!removed) logger.warning("Minion 12 was not removed")
}| Argument | What it does |
|---|---|
restoreFloor | true puts the original floor back and clears what the minion grew. Use false when the blocks are gone already. |
giveItem | true gives the owner the minion item and its stored items, on their next join when they are offline. With false, both are gone. |
- The minion is deleted from the database first. Only then does it leave the world, so a failed delete never copies a minion.
- The future completes on the main thread. It is
trueonce the minion is deleted. It isfalsewhen there is no such minion, it is being removed already, or the delete failed. - Afterwards every rule's
onRemovedruns withRemoveReason.API, andMinionRemoveEventfires.
EventsLink to this section
| Event | Fields | When |
|---|---|---|
MinionPlaceEvent | player, typeId, tier, center | A player places a minion and every check passed. Cancel it to stop the placement. The player then sees "You can't place a minion here." |
MinionUpgradeEvent | player, minion, oldTier, newTier | After an upgrade was paid and saved, and the cost commands ran. |
MinionRemoveEvent | minion, reason, player | After a minion was removed. player is who picked it up or the admin who removed it, or null (console, API). |
RemoveReason is PICKUP (from the minion menu), ADMIN (/minion admin remove or removeid) or API (ALBMinionsAPI.remove, also used by the ALBSkyblock addon).
class MinionListener(private val plugin: JavaPlugin) : Listener {
@EventHandler
fun onPlace(event: MinionPlaceEvent) {
if (event.typeId == "slayer" && !event.player.hasPermission("myplugin.slayer")) event.isCancelled = true
}
@EventHandler
fun onUpgrade(event: MinionUpgradeEvent) {
if (event.newTier == 5) event.player.sendMessage(Component.text("Your minion reached tier V!"))
}
@EventHandler
fun onRemove(event: MinionRemoveEvent) {
plugin.logger.info("Minion ${event.minion.id} removed (${event.reason})")
}
}