Adding a trigger
What to change to add a new animation event to hAnimationsWorks — the enum, the config folder, the listener, and the command wiring.
A trigger is an event that can play an animation. Adding one touches four places. The example adds a LEVEL_UP trigger.
:core compiles against Spigot 1.20.1. If your event or its API does not exist there, the change belongs in a distribution module or behind a seam — not in :core.
1. Add the enum constant
api/src/main/java/systems/homestead/hanimationsworks/api/AnimationTrigger.java
public enum AnimationTrigger {
JOIN,
QUIT,
// ...
LEVEL_UP,
}This is the order that matters. Ids are per-trigger, and a bare id with no trigger resolves to the first owner in AnimationTrigger.values() order. Adding a constant changes what an unqualified /hanim play <id> previews when that id exists under several triggers — append rather than insert if you do not want to shift existing behaviour.
The enum name is what appears in commands and completion, lowercased with underscores turned into hyphens: LOW_HEALTH → low-health. It does not have to match the config folder name, but keeping them close saves confusion — see step 2.
2. Add the config folder
core/src/main/resources/defaults/events/level_up/config.yml
# Level-up animations.
#
# One entry per animation. Every key under `animations` becomes an id that
# /hanim and other plugins can reference by name.
animations:The folder name is the file-system key. Check how readAll() derives its map key — the reader, not the enum, decides how a folder becomes a trigger, and they should agree.
Every other event folder is discovered automatically. There is no registry to update.
3. Handle the event
core/src/main/java/systems/homestead/hanimationsworks/core/listener/AnimationListeners.java
Add one @EventHandler that funnels through request:
@EventHandler
public void onLevelUp(@NotNull PlayerLevelChangeEvent event) {
if (event.getOldLevel() >= event.getNewLevel()) {
return;
}
request(event.getPlayer(), AnimationTrigger.LEVEL_UP);
}request(player, trigger) is the single place that asks "does this player want this?" — it consults the preference and plays only if one is stored. Do not call the engine directly from a listener; every handler goes through request so the preference lookup cannot drift between triggers.
PlayerLevelChangeEvent fires on both gain and loss, so the guard is required. A listener that does not check direction will play a level-down animation too.
Guards worth copying
Several existing handlers carry a note explaining a guard they added because the raw event is too eager. Follow them:
onBedEnter— the event fires for a player who merely sat on a bed. CheckBedEnterResult.OK, and ignore a cancelled event rather than playing anyway.onCommand—resolveForanswers "did this player choose anything for COMMAND", which is true for the whole session. Compare the chosen value against the command actually typed, or one preference cancels every command on the server.onAdvancementDone—Advancement.getDisplay()is@Nullableand returnsnullfor recipe-unlock advancements. The title is only ever logged, so fall back to the key.requireNonNullhere threw on the main thread every time somebody unlocked a recipe.
Deferring, when it matters
If the server applies state after the handler returns — sleep does — schedule past the event, or the animation is built against a state that is about to change:
Bukkit.getScheduler().runTask(plugin, () -> { /* ... */ });onBedEnter does exactly this, one tick later.
4. Wire the command
Nothing to do. BrigadierAnimationCommand completes triggers from AnimationTrigger.values(), so a new constant appears in /hanim picker <trigger>, set, clear, get and list automatically.
Check AnimationCommand — the legacy Bukkit fallback — for the same. Its subcommand list and its onTabComplete trigger list are hand-written arrays, and a trigger that is missing from one of them shows up only on servers where Brigadier cannot register.
Verify
./gradlew build— all three jars- Add an animation under
events/level_up/config.yml /hanim reload/hanim list level-up— the count should include it/hanim test <id>— preview it without triggering the event/hanim picker— the new event appears in the ring- Trigger it for real
A green build proves the code compiles, not that the event fires. Step 7 is the only one that proves the handler is wired to the event you think it is.
Verifying the artifact, not the source
After building, confirm the change is in the jar:
javap -p -classpath <jar> <fqcn> | grep <newMethod>A green build against a stale jar is the single most common false positive in this project.