Class PetBehaviorRegistry

java.lang.Object
de.Keyle.MyPet.api.behavior.PetBehaviorRegistry

public final class PetBehaviorRegistry extends Object
Central registry of every PetBehavior declared as a static field on a pet class. Populated as a side effect of each behavior's factory call (PetBehaviorHelpers.onPetInteract(java.lang.String, de.Keyle.MyPet.api.behavior.PetEventHandler<org.bukkit.event.player.PlayerInteractEntityEvent>), etc.) which fires during the pet class's <clinit>.

Plugin-side PetBehaviorDispatcher reads this at startup and registers one Bukkit EventExecutor per behavior, routing live events through PetBehavior.handler after pet-type filtering.

ensurePetsLoaded() force-initializes every registered pet class via Class.forName(true) so the registry is fully populated before the dispatcher iterates.

  • Method Details

    • ensurePetsLoaded

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

      public static void setDispatchHook(Consumer<PetBehavior<?>> hook)
      Installs a callback fired for every subsequent register(de.Keyle.MyPet.api.behavior.PetBehavior<?>). PetBehaviorDispatcher sets this after wiring the initial set, so behaviors registered later (third-party plugin onEnable) get a Bukkit executor too.

      The hook is responsible for its own deduplication if it also iterates all() — a behavior registered during the dispatcher's initial pass may surface here too if registration happens concurrently.

      Parameters:
      hook - called for each behavior registered from now on, or null to clear
    • all

      public static List<PetBehavior<?>> all()
      Returns a snapshot of every registered behavior. Iteration order matches registration order. Used by the plugin-side dispatcher at startup to wire each behavior to a Bukkit EventExecutor.
      Returns:
      every registered behavior, in registration order
    • eventClasses

      public static List<Class<? extends Event>> eventClasses()
      Returns the set of distinct event classes any registered behavior cares about. Convenience for dispatchers that want to iterate event-class-keyed rather than behavior-keyed.
      Returns:
      the distinct event classes any behavior listens for