Class PetBehavior<E extends Event>

java.lang.Object
de.Keyle.MyPet.api.behavior.PetBehavior<E>
Type Parameters:
E - the Bukkit event type this behavior is dispatched for

public final class PetBehavior<E extends Event> extends Object
One per-pet event handler, dispatched by the central PetBehaviorDispatcher. Built via PetBehaviorHelpers factories (PetBehaviorHelpers.onPetInteract(java.lang.String, de.Keyle.MyPet.api.behavior.PetEventHandler<org.bukkit.event.player.PlayerInteractEntityEvent>), etc.) — direct construction is package-private to enforce that helpers own the entity-extraction logic for each event type.

Each instance self-registers with PetBehaviorRegistry on construction so the dispatcher can iterate every behavior at startup without further wiring.

  • Method Details

    • eventClass

      public Class<E> eventClass()
      Bukkit event class this behavior listens for.
      Returns:
      the Bukkit event class this behavior listens for
    • petType

      public String petType()
      Pet type name (e.g. "Creeper") this behavior applies to.
      Returns:
      the pet type this behavior fires for
    • priority

      public EventPriority priority()
      Bukkit event priority — most behaviors are EventPriority.NORMAL.
      Returns:
      the priority this behavior listens at
    • ignoreCancelled

      public boolean ignoreCancelled()
      Whether the handler skips already-cancelled events.
      Returns:
      true if cancelled events are skipped
    • entityExtractor

      public Function<E,Entity> entityExtractor()
      Pulls the entity of interest out of event so the dispatcher can route based on its pet membership. PlayerInteractEntityEvent returns getRightClicked(); EntityDamageEvent returns getEntity(); etc. Each PetBehaviorHelpers factory bakes in the right extractor for its event type.
      Returns:
      pulls the candidate entity out of the event
    • handler

      public PetEventHandler<E> handler()
      The actual handler — invoked by the dispatcher after pet-type match.
      Returns:
      the handler run once the pet has been matched
    • alsoWhileDespawning

      public PetBehavior<E> alsoWhileDespawning()
      Keeps this behavior applying to a pet's host while it plays its despawn animation.

      When a modeled pet is sent away or stored, its host mob outlives the Pet for the length of the model's despawn animation. The pet is already despawned and the host is no longer a registered pet entity, so by default no behavior fires for it — the right thing for behaviors that react to the world acting on the pet (interaction, damage taken, lightning). Behaviors that gate what the host's body does to the world (an Ender Dragon's block destruction, contact damage, wing knockback) must keep applying, or the animating host does the very thing the gate exists to stop. The handler still receives the (despawned) pet, so it can read per-type config, but must not expect a live pet.getBukkitEntity().

      Returns:
      this behavior, for chaining in a static final initializer
    • appliesWhileDespawning

      public boolean appliesWhileDespawning()
      Whether the dispatcher also fires this behavior for a host that is still playing its despawn animation after its pet has been despawned.
      Returns:
      true if alsoWhileDespawning() was called