Class PetNameEvent

All Implemented Interfaces:
Cancellable

public class PetNameEvent extends CancellablePetEvent
Fired when a pet's display name is about to change. Listeners can rewrite the proposed name via setNewName(String) — useful for filtering profanity, enforcing length / character constraints, or applying server-wide formatting rules (color codes, bracket prefixes, etc.).

Fires from Pet#setPetName for every name change source — owner rename via /mypet name, admin rename via /petadmin name, and any third-party setter call. The new name is applied with the value of getNewName() at the end of the event dispatch, so listeners that mutate it later in the chain win over earlier ones.

Cancellable: cancellation suppresses the rename entirely — the pet keeps its current name.

Pet state: live pet (name changes only happen on active pets).

Format note: the name string is in MiniMessage format — Pet#getDisplayName deserializes it into a Component via the sanitized MiniMessage parser. Listeners modifying the name should preserve MiniMessage syntax.

  • Constructor Details

    • PetNameEvent

      public PetNameEvent(Pet pet, String newName)
      Creates the event for a pending rename.
      Parameters:
      pet - the pet being renamed
      newName - the proposed name, in MiniMessage format
  • Method Details

    • getHandlerList

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

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

      public Pet getPet()
      The pet being renamed.
      Specified by:
      getPet in class PetEvent
      Returns:
      the pet being renamed
    • getNewName

      public String getNewName()
      The name that will be applied, in MiniMessage format. Listeners may rewrite it; the value present when dispatch ends is the one that sticks, so a later listener overrides an earlier one. Keep the MiniMessage syntax intact when modifying it.
      Returns:
      the name that will be applied, in MiniMessage form
    • setNewName

      public void setNewName(String newName)
      The name that will be applied, in MiniMessage format. Listeners may rewrite it; the value present when dispatch ends is the one that sticks, so a later listener overrides an earlier one. Keep the MiniMessage syntax intact when modifying it.
      Parameters:
      newName - the value to set