Package de.Keyle.MyPet.api.lifecycle
Class PetLifecycleHook
java.lang.Object
de.Keyle.MyPet.api.lifecycle.PetLifecycleHook
Per-pet-type runtime hook fired when a pet spawns and despawns. Used by
pet-specific visual controllers, schedulers, and AI suppressors whose
activation/cleanup needs to run alongside the Bukkit entity lifecycle.
Declared as a static field on the matching PetXxx class:
public static final PetLifecycleHook LIFECYCLE_HOOK = new PetLifecycleHook(
"Creaking",
ActivationSuppressor::startForPet,
ActivationSuppressor::stopForPet
);
Construction self-registers with PetLifecycleHookRegistry, so
shared spawn/despawn code in PetImpl, VanillaMobSpawner,
and PetManager iterates hooks via PetLifecycleHookRegistry.forPet(de.Keyle.MyPet.api.entity.Pet)
without naming any specific pet type.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PetLifecycleHookBuilds a hook that fires for every pet, regardless of type.voidRuns the despawn callback.voidRuns the spawn callback.petType()Returns the pet type this hook is bound to.
-
Constructor Details
-
PetLifecycleHook
Declares a hook for one pet type, registering itself as it is built.- Parameters:
petType- the pet type this hook fires foronSpawn- run when such a pet spawnsonDespawn- run when such a pet despawns
-
-
Method Details
-
global
Builds a hook that fires for every pet, regardless of type. Useful for cross-cutting per-spawn/despawn behavior that is not specific to a species.- Parameters:
onSpawn- run when any pet spawnsonDespawn- run when any pet despawns- Returns:
- the registered hook
-
petType
Returns the pet type this hook is bound to.- Returns:
- the pet type name, or
nullfor a global hook
-
onSpawn
Runs the spawn callback.- Parameters:
pet- the pet that just spawned
-
onDespawn
Runs the despawn callback.- Parameters:
pet- the pet that just despawned
-