Class PetLifecycleHookRegistry

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

public final class PetLifecycleHookRegistry extends Object
Central registry of every PetLifecycleHook declared as a static field on a pet class. Populated as a side effect of each hook's constructor, which fires during the pet class's <clinit>.

forPet(Pet) returns the hooks registered for the given pet's type — shared spawn/despawn code in PetImpl, VanillaMobSpawner, and PetManager iterates the result without naming any specific pet type. Adding a new pet-specific lifecycle hook is a one-line declaration on the pet class; no shared file is touched.

ensurePetsLoaded() force-initializes every registered pet class via Class.forName(true) so the registry is fully populated before the first spawn-side iteration.

  • Method Details

    • ensurePetsLoaded

      public static void ensurePetsLoaded()
      Force-initializes every registered pet class via Class.forName(true) so each one's static PetLifecycleHook field initializers fire and register with this registry. Idempotent; runs once per JVM.
    • forPet

      public static List<PetLifecycleHook> forPet(Pet pet)
      Returns every lifecycle hook registered for pet's type, in registration order. Returns an empty list when no hook is registered.
      Parameters:
      pet - the pet whose type to look up
      Returns:
      the hooks to run for that pet, global hooks included