Class PetBehavior<E extends Event>
- Type Parameters:
E- the Bukkit event type this behavior is dispatched for
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 Summary
Modifier and TypeMethodDescriptionKeeps this behavior applying to a pet's host while it plays its despawn animation.booleanWhether the dispatcher also fires this behavior for a host that is still playing its despawn animation after its pet has been despawned.Pulls the entity of interest out ofeventso the dispatcher can route based on its pet membership.Bukkit event class this behavior listens for.handler()The actual handler — invoked by the dispatcher after pet-type match.booleanWhether the handler skips already-cancelled events.petType()Pet type name (e.g.priority()Bukkit event priority — most behaviors areEventPriority.NORMAL.
-
Method Details
-
eventClass
Bukkit event class this behavior listens for.- Returns:
- the Bukkit event class this behavior listens for
-
petType
Pet type name (e.g."Creeper") this behavior applies to.- Returns:
- the pet type this behavior fires for
-
priority
Bukkit event priority — most behaviors areEventPriority.NORMAL.- Returns:
- the priority this behavior listens at
-
ignoreCancelled
public boolean ignoreCancelled()Whether the handler skips already-cancelled events.- Returns:
trueif cancelled events are skipped
-
entityExtractor
Pulls the entity of interest out ofeventso the dispatcher can route based on its pet membership.PlayerInteractEntityEventreturnsgetRightClicked();EntityDamageEventreturnsgetEntity(); etc. EachPetBehaviorHelpersfactory bakes in the right extractor for its event type.- Returns:
- pulls the candidate entity out of the event
-
handler
The actual handler — invoked by the dispatcher after pet-type match.- Returns:
- the handler run once the pet has been matched
-
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
Petfor 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 livepet.getBukkitEntity().- Returns:
- this behavior, for chaining in a
static finalinitializer
-
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:
trueifalsoWhileDespawning()was called
-