Class PetExpEvent

All Implemented Interfaces:
Cancellable

public class PetExpEvent extends CancellablePetEvent
Fired before a pet's experience changes — gain or loss. Dispatched once per change from the central PetExperience#updateExp flow that backs addExp, removeExp, and the percent-add helpers.

Fires from PetExperience immediately before the exp delta is applied and the level is recomputed.

Cancellable: cancellation skips the exp change entirely — updateExp returns 0 and the level recomputation does not happen, so no follow-up PetLevelUpEvent or PetLevelDownEvent is dispatched.

Mutable delta: setExp(double) adjusts the value to be applied — useful for multipliers (XP-boost potions) or caps. The signed value reflects the direction (positive for gain, negative for loss); the post-clamp result is also bounded by 0..maxExp on the pet side.

Quiet flag: isQuiet() mirrors the caller's quiet preference and is propagated forward to PetLevelUpEvent / PetLevelDownEvent if the level changes.

Pet state: live pet (experience changes only happen on the runtime).

  • Constructor Details

    • PetExpEvent

      public PetExpEvent(Pet pet, double exp, boolean quiet)
      Creates the event for an experience change.
      Parameters:
      pet - the pet gaining or losing experience
      exp - the signed experience delta
      quiet - true to suppress the usual player-facing messaging
    • PetExpEvent

      public PetExpEvent(Pet pet, double exp)
      Creates the event for a non-quiet experience change.
      Parameters:
      pet - the pet gaining or losing experience
      exp - the signed experience delta
  • Method Details

    • getHandlerList

      public static HandlerList getHandlerList()
      Returns the handler list for this event type.
      Returns:
      the shared HandlerList every PetExpEvent is dispatched through
    • getHandlers

      public @NonNull HandlerList getHandlers()
      Specified by:
      getHandlers in class Event
    • getPet

      public Pet getPet()
      The pet whose experience is about to change.
      Specified by:
      getPet in class PetEvent
      Returns:
      the pet whose experience is changing
    • isQuiet

      public boolean isQuiet()
      Whether the caller asked for the change to be silent. Propagated to PetLevelUpEvent / PetLevelDownEvent if the level moves.
      Returns:
      true if player-facing messaging is suppressed
    • getExp

      public double getExp()
      The signed experience delta about to be applied -- positive for a gain, negative for a loss. Listeners may rewrite it to apply multipliers or caps; the pet clamps the result to its own 0..maxExp range.
      Returns:
      the signed experience delta about to be applied
    • setExp

      public void setExp(double exp)
      The signed experience delta about to be applied -- positive for a gain, negative for a loss. Listeners may rewrite it to apply multipliers or caps; the pet clamps the result to its own 0..maxExp range.
      Parameters:
      exp - the value to set