Events
Listen for and modify pet behavior via the MyPet event API.
MyPet publishes 23 event classes in the de.Keyle.MyPet.api.event package. They integrate with Bukkit's standard Listener / @EventHandler pattern. Some implement Cancellable; others carry mutable getters and setters that let you change behavior without cancelling.
Migrating from MyPet 3.x? Every event class was renamed from MyPet*Event to Pet*Event, the getMyPet() accessor on each event is now getPet(), and the nested source / action / result enums moved from PascalCase to UPPER_SNAKE_CASE (e.g. Source.Leash is now Source.LEASH). Two events — MyPetActiveSkillEvent and MyPetActiveTargetSkillEvent — were removed outright. See Migrating from v3.x for the full porting guide.
How to listen
Implement org.bukkit.event.Listener, mark your handler methods with @EventHandler, and register the listener in your plugin's onEnable():
package com.example.mypetintegration;
import de.Keyle.MyPet.api.event.PetLevelUpEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public final class MyPlugin extends JavaPlugin implements Listener {
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler(priority = EventPriority.NORMAL)
public void onLevelUp(PetLevelUpEvent event) {
getLogger().info(event.getOwner().getName() + "'s pet leveled up!");
}
}Use EventPriority to control ordering relative to other plugins listening for the same event. For events that mutate values (e.g. PetDamageEvent#setDamage), prefer MONITOR only for read-only inspection — modifications belong on LOWEST–HIGHEST.
Lifecycle
PetCreateEvent
Fires when a new pet enters a player's collection — via leashing, the pet shop, or an admin command. Not cancellable; by the time it fires the pet already exists. Carries a nested Source enum (LEASH, ADMIN_COMMAND, PET_SHOP, OTHER).
Accessors
getSource()— which path created this petgetPet()— the newStoredPetgetOwner()— the owningMyPetPlayergetPlayer()— the owning BukkitPlayer
PetLoadEvent
Fires when a pet is loaded from the repository — typically the first time its owner is seen on the server after a restart. Not cancellable.
Accessors
getPet()— the loadedStoredPetgetOwner()— the owningMyPetPlayergetPlayer()— the owning BukkitPlayer(may be null if the owner is not online yet)
PetCallEvent
Cancellable
Fires when an owner summons their pet into the world. Cancelling prevents the pet from spawning. The pet exposed via getPet() is guaranteed to be live (skills loaded, NBT applied) when this event fires — see the migration notes if you're porting code that expected the old StoredMyPet base type.
Accessors
getPet()— the livePetbeing summonedgetOwner()— the owningMyPetPlayergetPlayer()— the owning BukkitPlayer
PetSendAwayEvent
Cancellable
Fires when an owner sends their pet away (despawning it back to storage). Cancelling keeps the pet present.
Accessors
getPet()— theStoredPetbeing sent awaygetOwner()— the owningMyPetPlayergetPlayer()— the owning BukkitPlayer
PetSaveEvent
Fires when a pet is persisted to the configured repository. Not cancellable.
Accessors
getPet()— theStoredPetbeing savedgetOwner()— the owningMyPetPlayergetPlayer()— the owning BukkitPlayer
Save operations may run on a worker thread when using a remote backend (e.g. MySQL). Schedule any Bukkit-API work back to the main thread with Bukkit.getScheduler().runTask(...) if needed. On Folia, hop to a region scheduler instead.
PetRemoveEvent
Fires when a pet is removed from its owner's collection. Not cancellable. Carries a nested Source enum (RELEASE, DEATH, ADMIN_COMMAND, OTHER) explaining why.
Accessors
getSource()— why the pet was removedgetPet()— the removedStoredPetgetOwner()— the (former) owningMyPetPlayergetPlayer()— the owning BukkitPlayer
PetPlayerJoinEvent
Fires when a MyPetPlayer joins the server (separate from Bukkit's own PlayerJoinEvent so MyPet-aware code can reliably react after the player's pet data is ready). Not cancellable.
Accessors
getPlayer()— the joiningMyPetPlayer
v4 break: getPlayer() returns MyPetPlayer, not Bukkit Player. If you need the Bukkit Player, call event.getPlayer().getPlayer(). MyPetPlayer.sendMessage takes an Adventure Component, not a String, so any 3.x code that called event.getPlayer().sendMessage("text") will fail to compile against 4.0.
Combat & Skills
PetDamageEvent
Cancellable
Fires when an active pet is about to deal damage to another entity. Both setDamage(double) (clamped to ≥0) and setCancelled(true) are supported, so you can reduce, eliminate, or cancel the hit.
Accessors
getPet()— the attackingPetgetTarget()— the BukkitEntitytaking damagegetDamage()/setDamage(double)— the outgoing damage amountgetOwner()— the owningMyPetPlayergetPlayer()— the owning BukkitPlayer
PetOnHitSkillEvent
Cancellable
Fires when an OnHitSkill (e.g. Fire, Poison, Thorns) is about to apply on a successful hit. Cancel to suppress the skill effect for this hit only. This is the canonical hook for "react when a skill triggers" — the standalone MyPetActiveSkillEvent from 3.x has been removed.
Accessors
getPet()— the attackingPetgetSkill()— theOnHitSkillinstance about to triggergetTarget()— theLivingEntitybeing hitgetOwner()— the owningMyPetPlayergetPlayer()— the owning BukkitPlayer
Experience & Progression
PetExpEvent
Cancellable
Fires when XP is being awarded to a pet (from kills, the experience system, or admin commands). Cancel to deny the XP entirely, or use setExp(double) to scale it.
Accessors
getPet()— thePetreceiving XPgetExp()/setExp(double)— the XP amountisQuiet()— whether MyPet should suppress its own chat / sound feedback for this gaingetOwner()— the owningMyPetPlayergetPlayer()— the owning BukkitPlayer
PetLevelEvent
Parent class of PetLevelUpEvent and PetLevelDownEvent. Listening for it directly catches both directions; listen for the specific subclass when you only care about one. Not cancellable.
Accessors
getPet()— thePetgetLevel()— the new (post-change) levelisQuiet()— whether MyPet should suppress its own feedbackgetOwner()— the owningMyPetPlayergetPlayer()— the owning BukkitPlayer
PetLevelUpEvent
Subclass of PetLevelEvent. Fires when a pet gains a level. Adds fromLevel() (note: no get prefix — record-style accessor).
Accessors
fromLevel()— the previous level(plus all accessors from
PetLevelEvent)
PetLevelDownEvent
Subclass of PetLevelEvent. Fires when a pet loses a level (e.g. via admin command or scripted XP loss). Adds fromLevel().
Accessors
fromLevel()— the previous (higher) level(plus all accessors from
PetLevelEvent)
PetSelectSkilltreeEvent
Fires when a skilltree is assigned to a pet — by player command, admin action, the pet shop, or the auto-assignment logic. Not cancellable. Carries a nested Source enum (AUTO, PLAYER_COMMAND, ADMIN_COMMAND, ADMIN_CREATION, SHOP, OTHER).
Accessors
getSource()— what triggered the selectiongetSkilltree()— theSkilltreebeing assignedgetPet()— theStoredPetgetOwner()— the owningMyPetPlayergetPlayer()— the owning BukkitPlayer
Interaction & State
PetActivatedEvent
Fires once a summoned pet is fully active in the world (after PetCallEvent has succeeded and the underlying mob has spawned). Not cancellable; use PetCallEvent if you need to block the spawn.
Accessors
getPet()— the now-activePetgetOwner()— the owningMyPetPlayergetPlayer()— the owning BukkitPlayer
PetStatusEvent
Fires when a pet's PetState changes (e.g. between Here, Despawned, Dead). Not cancellable.
Accessors
getPet()— thePetwhose state changedgetState()— the newPet.PetStatethe pet just transitioned togetOwner()— the owningMyPetPlayergetPlayer()— the owning BukkitPlayer
PetSitEvent
Cancellable (inherits from PetInteractEvent)
Fires when a pet is told to stay or follow. Adds getAction() returning a nested Action enum (STAY, FOLLOW).
Accessors
getAction()—STAYorFOLLOWgetPet()— the affectedPet(inherited)
PetInteractEvent
Cancellable
Parent class for interaction events. Fires when a player right-clicks their pet. Cancel to suppress the default interaction behavior. PetSitEvent and PetFeedEvent extend this — listen to those if you want the more specific contexts.
Accessors
getPet()— thePetbeing interacted withgetItem()— theItemStackthe player was holding (new in 4.0; previously only available onPetFeedEvent)
PetInventoryActionEvent
Cancellable
Fires when a player or the pet itself acts on the pet's backpack inventory. Carries a nested Action enum (OPEN, PICKUP, USE).
Accessors
getAction()— what kind of inventory action this isgetPet()— thePetwhose inventory is involvedgetOwner()— the owningMyPetPlayergetPlayer()— the owning BukkitPlayer
PetNameEvent
Cancellable (new in 4.0)
Fires when a pet is being renamed. Cancelling suppresses the rename; the pet keeps its current name. setNewName(String) lets you sanitize names by mutating the value before the rename completes.
Accessors
getPet()— thePetbeing renamedgetNewName()/setNewName(String)— the proposed new name
PetFeedEvent
Cancellable (inherits from PetInteractEvent)
Fires when a pet is fed. Both the saturation amount and the resulting effect (HEAL, EAT, SELF_FEED) are mutable.
Accessors
getSaturation()/setSaturation(double)— saturation gained from this feedinggetResult()/setResult(Result)— what feeding does for this hitgetPet()— thePet(inherited)getItem()— theItemStackbeing fed (inherited fromPetInteractEvent)
PetPickupItemEvent
Cancellable
Fires when a pet (with the Pickup skill) is about to grab a ground item.
Accessors
getItem()— the dropped BukkitItementitygetPet()— thePetdoing the pickupgetOwner()— the owningMyPetPlayergetPlayer()— the owning BukkitPlayer
Resources
PetExhaustionEvent
Cancellable
Fires when a pet is about to lose saturation from the hunger system. Cancel to keep the pet from getting hungry on this tick — useful for "creative-mode" pet plugins or temporary buffs.
Accessors
getPet()— thePetlosing saturationgetOwner()— the owningMyPetPlayergetPlayer()— the owning BukkitPlayer
Last updated
Was this helpful?
