Class PetLifecycleHook

java.lang.Object
de.Keyle.MyPet.api.lifecycle.PetLifecycleHook

public final class PetLifecycleHook extends Object
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 Details

    • PetLifecycleHook

      public PetLifecycleHook(String petType, Consumer<Pet> onSpawn, Consumer<Pet> onDespawn)
      Declares a hook for one pet type, registering itself as it is built.
      Parameters:
      petType - the pet type this hook fires for
      onSpawn - run when such a pet spawns
      onDespawn - run when such a pet despawns
  • Method Details

    • global

      public static PetLifecycleHook global(Consumer<Pet> onSpawn, Consumer<Pet> onDespawn)
      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 spawns
      onDespawn - run when any pet despawns
      Returns:
      the registered hook
    • petType

      public String petType()
      Returns the pet type this hook is bound to.
      Returns:
      the pet type name, or null for a global hook
    • onSpawn

      public void onSpawn(Pet pet)
      Runs the spawn callback.
      Parameters:
      pet - the pet that just spawned
    • onDespawn

      public void onDespawn(Pet pet)
      Runs the despawn callback.
      Parameters:
      pet - the pet that just despawned