Class PetEvent

java.lang.Object
org.bukkit.event.Event
de.Keyle.MyPet.api.event.PetEvent
Direct Known Subclasses:
CancellablePetEvent, PetActivatedEvent, PetCreateEvent, PetLevelEvent, PetLoadEvent, PetRemoveEvent, PetSaveEvent, PetSelectSkilltreeEvent, PetStatusEvent

public abstract class PetEvent extends Event
Common base of every MyPet event that concerns one specific pet. It gives addon code a single type to accept, store or test with instanceof when it only needs to know which pet an event is about and who owns it, and it holds the owner and player accessors that every pet event shares.

Listening: this class is abstract and, like Bukkit's own BlockEvent or PlayerEvent, has no handler list of its own, so it cannot be passed to an @EventHandler method directly. Register against a concrete event such as PetCallEvent; use PetEvent for helper methods and type checks inside the handler.

Pet type: getPet() is declared as the widest type, StoredPet. Events that only fire for a live pet narrow the return type to Pet in their own override, so existing listeners keep compiling and linking unchanged.

Events that carry a pet but are not cancellable extend this class directly; the cancellable ones extend CancellablePetEvent.

  • Constructor Details

    • PetEvent

      protected PetEvent()
      Creates a synchronous pet event.
  • Method Details

    • getPet

      public abstract StoredPet getPet()
      Returns the pet this event concerns.
      Returns:
      the pet; concrete events narrow this to Pet when the pet is guaranteed to be live
    • getOwner

      public MyPetPlayer getOwner()
      Returns the owner of the pet this event concerns.
      Returns:
      the pet's owner
    • getPlayer

      public Player getPlayer()
      Returns the Bukkit player behind the pet's owner.
      Returns:
      the owner's Player, valid only while MyPetPlayer.isOnline() is true