ALB Studio

Hooks

PlaceholderAPI, Vault, PacketEvents, Nexo, ModelEngine models and WorldGuard regions, plus ItemRef for items in config files.

Docs updated · What changed

On this page

PlaceholderAPILink to this section

Kotlin
PAPIHook.register(this, "myplugin", "total") { player -> totalOf(player).toString() }  // %myplugin_total%
PAPIHook.register(this, "level") { player -> PlayerData.getInt(player, "level", 1).toString() }  // %alb_level% (shared)
val text = PAPIHook.parse(player, "Balance: %vault_eco_balance%")
  • Each identifier becomes its own PlaceholderAPI expansion, created on first use.
  • Identifiers use a-z and 0-9 only (PlaceholderAPI splits at the first _); keys use a-z, 0-9 and _.
  • Handlers can be called from async threads, so only read thread-safe data.
  • They are removed automatically when your plugin disables, and they survive /papi reload.

VaultLink to this section

Kotlin
if (VaultHook.withdraw(player, 250.0)) { /* paid */ }
VaultHook.getBalance(player); VaultHook.has(player, 100.0); VaultHook.deposit(player, 50.0); VaultHook.format(1500.0)

Works with any economy registered through Vault or VaultUnlocked, even if it loads after ALBCore. Without an economy, reads return 0 and changes return false.

PacketEventsLink to this section

Kotlin
if (PacketEventsHook.isEnabled()) PacketEventsHook.register(this, MyPacketListener())

NexoLink to this section

Since 1.4.0

Kotlin
val ore = NexoHook.item("bloodstone", 16)           // ItemStack? (null: no such item / no Nexo)
val id = NexoHook.idOf(player.inventory.itemInMainHand)   // "bloodstone" or null for vanilla
NexoHook.exists(id); NexoHook.isBlock(id); NexoHook.ids()
NexoHook.blockData("bloodstone")      // BlockData that shows the custom block (e.g. for BlockFormEvent.newState)
NexoHook.place("bloodstone", location); NexoHook.blockIdAt(block)

Nexo is reached by reflection through its own class loader, so neither ALBCore nor your plugin depends on it. Every call is safe without Nexo (null / false / empty). Nexo loads its items shortly after startup.

ModelEngineLink to this section

Since 1.5.0

Spawn ModelEngine (R4) models and drive them from code: animations, bones and clicks. The models live on packet-only entities: no real entity, nothing saved with the world, no AI.

ALBCore's API has no ModelEngine types, so your plugin needs no ModelEngine dependency: no compileOnly, nothing in plugin.yml. Every call is safe without ModelEngine (false / null / empty). If the installed ModelEngine's API does not match (ALBCore is built against R4.1.1), ALBCore logs one warning and models stay off.

Check and spawnLink to this section

Kotlin
ModelEngineHook.isAvailable()                       // ModelEngine is on and its API works
ModelEngineHook.hasModel("minion")                  // the model is loaded
ModelEngineHook.animations("minion")                // Set<String> (empty: not loaded)
ModelEngineHook.animationLength("minion", "work")   // seconds, or null

val model = ModelEngineHook.spawn(this, "minion", location, ModelOptions(
    viewRange = 32,
    hitbox = ModelHitbox(width = 0.6, height = 1.2, depth = 0.6, eyeHeight = 1.0),
)) ?: return
model.play("idle")   // same tick as spawn: players never see the bind pose

spawn returns a ModelHandle, or null when ModelEngine is not available, the model is not loaded (yet), your plugin is disabled or the location has no world. The location's yaw turns the model. The model stays hidden for revealDelayTicks, so play its first animation right after spawn, in the same tick.

ModelOptionsDefaultWhat it does
viewRange48Blocks from which players see the model (must be positive).
hitboxnullModelHitbox(width, height, depth, eyeHeight) in blocks. Null uses the blueprint's own hitbox.
hitboxVisibletrueModelEngine's hitbox visibility. Keep it true for models players click.
shadowtrueWhether the model casts its blueprint shadow.
canHurtfalseWhether the model flashes red when hit.
culltrueFalse turns off ModelEngine's blocked and vertical culling, for models that must stay visible behind blocks or far above or below the viewer (e.g. in a cutscene).
stateAnimationsfalseFalse turns off ModelEngine's automatic state animations (idle, walk, spawn, death...), so only the animations you play run. True keeps ModelEngine's.
revealDelayTicks3Ticks the model stays hidden after spawning, so the first animation is in place when players see it. 0 shows it at once.

AnimationsLink to this section

Kotlin
model.play("work", lerpIn = 0.1, lerpOut = 0.2, speed = 1.0, force = true)   // true if it started
model.isPlaying("work")
model.stop("work")        // blends out over its lerp-out time
model.forceStop("work")   // stops at once
model.stopAll()           // stops every animation at once
  • Lerp times are in seconds and speed 1.0 is normal speed. Defaults: lerpIn = 0.0, lerpOut = 0.2, speed = 1.0, force = true.
  • With force, play replaces the same animation if it is already playing.
  • play returns false when the model has no such animation, the animation is already playing and force is false, another plugin cancelled it, or the model was removed.
  • Whether an animation loops, holds its last frame or plays once comes from the animation itself, as set in Blockbench.
  • isPlaying stays true while the animation blends out.

Bones, visibility and movementLink to this section

Kotlin
model.boneVisible("hat", false)                            // false: no such bone
model.boneItem("tool", ItemStack(Material.IRON_PICKAXE))   // null clears it
model.setVisible(false)                                    // hide the whole model for everyone
model.teleport(location)                                   // yaw turns body and head, pitch tilts the head
model.rotate(90f)                                          // turn without moving
  • boneItem only works on bones with ModelEngine's item behaviour. It returns false for other bones and does not change a normal bone's look.
  • Hiding a model during its reveal delay keeps it hidden.
  • model.location is a copy of where the model stands. model.valid is false once it was removed.

ClicksLink to this section

Kotlin
model.onClick { player, click ->
    if (click.right) openMenu(player)
    else if (click.sneaking) player.sendMessage("You hit it while sneaking")
}
  • Only main-hand clicks count. click.right is a right-click and click.left a left-click (attack). click.sneaking tells if the player was sneaking.
  • Clicks land on the model's hitbox: ModelOptions.hitbox, or the blueprint's own when that is null.
  • Handlers run on the main thread, in the order you added them. A failing handler is logged and the others still run.

Reloads and cleanupLink to this section

Kotlin
ModelEngineHook.onModelsReloaded(this) { respawnAll() }
ModelEngineHook.handles(this)          // your models that were not removed yet
ModelEngineHook.unregisterAll(this)    // remove all your models and reload callbacks
model.remove()                         // safe to call twice
  • ModelEngine loads its models a moment after the server starts, and again on /meg reload. Until a model is loaded, spawn returns null.
  • onModelsReloaded runs on the main thread after each load. Models spawned before a reload keep the old blueprint, so remove and respawn them there.
  • If your plugin enables after the models are already loaded, spawn when hasModel is true.
  • Your models and reload callbacks are removed automatically when your plugin disables, so onDisable needs nothing.
  • If ModelEngine itself is disabled while the server runs, models stay off until the next restart.

Example: a minionLink to this section

A minion model that idles, plays its work animation, opens its menu on right-click and goes away with the minion. Its idle animation is set to loop in Blockbench. Minion and openMinionMenu are your plugin's own.

Kotlin
class MinionModels(private val plugin: JavaPlugin) {
    private val models = HashMap<UUID, ModelHandle>()   // minion id -> its model

    fun enable(minions: () -> List<Minion>) {
        // Models load after startup and again on /meg reload: (re)spawn them each time.
        ModelEngineHook.onModelsReloaded(plugin) { minions().forEach(::spawn) }
        if (ModelEngineHook.hasModel(MODEL)) minions().forEach(::spawn)
    }

    fun spawn(minion: Minion) {
        models.remove(minion.id)?.remove()
        val model = ModelEngineHook.spawn(plugin, MODEL, minion.location, ModelOptions(
            hitbox = ModelHitbox(width = 0.6, height = 1.0, depth = 0.6, eyeHeight = 0.8),
        )) ?: return
        model.play("idle")
        model.boneItem("tool", ItemStack(Material.IRON_PICKAXE))
        model.onClick { player, click -> if (click.right) openMinionMenu(player, minion) }
        models[minion.id] = model
    }

    fun work(minion: Minion) {
        val model = models[minion.id]?.takeIf { it.valid } ?: return
        model.stop("idle")
        model.play("work", lerpIn = 0.1)
        val ticks = ((ModelEngineHook.animationLength(MODEL, "work") ?: 1.0) * 20).toLong()
        plugin.server.scheduler.runTaskLater(plugin, Runnable {
            if (model.valid) model.play("idle", lerpIn = 0.2)
        }, ticks)
    }

    fun remove(minion: Minion) {
        models.remove(minion.id)?.remove()
    }

    companion object { const val MODEL = "minion" }
}

WorldGuardLink to this section

Since 1.6.0

Check WorldGuard 7 region rules from your plugin: may this player build, place, break or use something here, what does a flag say here, and which regions are here. ALBCore asks WorldGuard's own region query the same way WorldGuard's protection does, so region members and owners, priorities, parent regions and __global__ all count.

ALBCore's API has no WorldGuard types, so your plugin needs no WorldGuard dependency: no compileOnly, nothing in plugin.yml. ALBCore is built against WorldGuard 7.0.21 and WorldEdit 7.4.6.

ChecksLink to this section

Kotlin
WorldGuardHook.isAvailable()                     // WorldGuard 7 is on and its API works
WorldGuardHook.canBuild(player, location)        // BUILD
WorldGuardHook.canPlace(player, location)        // BUILD plus block-place
WorldGuardHook.canBreak(player, location)        // BUILD plus block-break
WorldGuardHook.canInteract(player, location)     // BUILD plus interact and use (doors, buttons...)
WorldGuardHook.testFlag(player, location, "pvp")           // any state flag by name
WorldGuardHook.testFlag(null, location, "mob-spawning")    // null player: the value for a non-member
WorldGuardHook.regionIds(location)               // ["spawn", ...], highest priority first
  • A player with region bypass (worldguard.region.bypass.<world>, not turned off with /rg bypass) is always allowed, and testFlag gives them true.
  • testFlag works with any registered state flag, built in or custom. It is true only for allow: a flag no region sets and without a default gives false. It returns null when the flag is unknown or is not a state flag.
  • regionIds does not include __global__.
  • Call the checks from the main thread.

Custom flagsLink to this section

Kotlin
override fun onLoad() {
    WorldGuardHook.registerFlag("minion-place", true)   // default allow; false without WorldGuard
}

Admins then set it per region, for example /rg flag spawn minion-place deny.

  • WorldGuard only accepts new flags before it enables, so call registerFlag from your plugin's onLoad. WorldGuard only has to be installed, not enabled.
  • Names use letters, digits, - and :. The second argument is the default: true means allow where no region sets the flag.
  • It returns true when a state flag with that name is ready, also when one is already registered (by another plugin or an earlier load). That flag is then reused with its own default.
  • It returns false when WorldGuard is not installed, it is too late, the name is invalid, or the name belongs to a flag that is not a state flag (logged).

Example: placing a minionLink to this section

A minion takes a 3×3 space, 2 blocks high, around the block it stands on. Every block of that space must allow placing, because a region can be smaller than the space and cover only part of it. minion-place lets admins turn minions off in a region while normal building stays allowed. Minion and lang are your plugin's own.

Kotlin
class MinionPlugin : JavaPlugin() {

    override fun onLoad() {
        WorldGuardHook.registerFlag("minion-place", true)
    }

    fun canPlaceMinion(player: Player, center: Location): Boolean {
        val world = center.world ?: return false
        for (x in -1..1) for (y in 0..1) for (z in -1..1) {
            val block = Location(world, center.blockX + x + 0.5, center.blockY + y + 0.5, center.blockZ + z + 0.5)
            if (!WorldGuardHook.canPlace(player, block)) return false
            if (WorldGuardHook.testFlag(player, block, "minion-place") == false) return false
        }
        return true
    }

    fun placeMinion(player: Player, center: Location) {
        if (!canPlaceMinion(player, center)) {
            lang.send(player, "minion.protected")
            return
        }
        Minion.spawn(player, center)
    }
}

testFlag(...) == false only stops on a real deny, so without WorldGuard (null) placing stays allowed.

Items in configs: ItemRefLink to this section

Since 1.4.0

Kotlin
val ref = ItemRef.parse("nexo:bloodstone")   // or "DIAMOND", "minecraft:diamond"
ref.matches(stack); ref.create(16); ref.displayName(); ref.isBlock(); ref.key   // "nexo:bloodstone"
ItemRef.of(stack)                                   // what a held item is
ItemRef.count(player, ref)
val taken = ItemRef.takeAll(player, mapOf(ref to 64, ItemRef.of(Material.STONE) to 64))  // all or nothing; null = short
ItemRef.giveBack(player, taken!!)                   // refund the very same stacks
ItemRef.give(player, ref, 128)                   // extra drops at the feet

Vanilla refs only match plain stacks: never Nexo items of the same material, renamed or enchanted items, damaged tools or filled containers. Nexo items are recognised by their nexo:id tag even while Nexo is off.

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