Record Class PersistedPet

java.lang.Object
java.lang.Record
de.Keyle.MyPet.api.entity.PersistedPet
Record Components:
uuid - the pet's persistent id; generated when absent
owner - the owning player; must not be null
petType - the species; defaults to Wolf when absent
petName - the raw name in MiniMessage form; empty when absent
worldGroup - the world group the pet belongs to; empty when absent
exp - accumulated experience
health - current health in half-hearts
saturation - hunger level, clamped to 1..100
respawnTime - seconds left on the respawn timer; 0 when alive
wantsToRespawn - whether the pet returns on the owner's next login
lastUsed - epoch milliseconds of the pet's last activity
skilltree - the assigned skilltree, or null when none is set
skillInfo - per-skill persisted state; empty when absent
info - addon-owned persisted state; empty when absent
volume - the pet's sound-volume override in [0, 1]; empty when the pet inherits its owner's setting
minDistanceStep - personal-space step, normalized to 1..5 (default 3 when out of range)
maxDistanceStep - follow-distance step, normalized to 1..5 (default 3 when out of range)
All Implemented Interfaces:
StoredPet

public record PersistedPet(UUID uuid, MyPetPlayer owner, PetType petType, String petName, String worldGroup, double exp, double health, double saturation, int respawnTime, boolean wantsToRespawn, long lastUsed, Skilltree skilltree, CompoundBinaryTag skillInfo, CompoundBinaryTag info, OptionalDouble volume, int minDistanceStep, int maxDistanceStep) extends Record implements StoredPet
Immutable, value-typed pet record — the canonical "pet at rest" representation that the repository loads from disk and that callers pass around between deactivation and reactivation.

Mutation pattern. Use PersistedPet.Builder (via builder(de.Keyle.MyPet.api.player.MyPetPlayer) or toBuilder()) for multi-field construction; use withX for single-field updates. Every "mutation" returns a new instance — callers that cached a prior reference must re-publish (e.g. repo.updatePet(newPet)).

Validation. The compact constructor normalizes inputs: saturation is clamped to [1, 100] (and coerced to 100 with a warning if NaN/Infinite); empty info/null skillInfo become CompoundBinaryTag.empty(); uuid is generated if absent; petType defaults to Wolf; petName and worldGroup default to empty strings.

  • Constructor Details

    • PersistedPet

      public PersistedPet(UUID uuid, MyPetPlayer owner, PetType petType, String petName, String worldGroup, double exp, double health, double saturation, int respawnTime, boolean wantsToRespawn, long lastUsed, Skilltree skilltree, CompoundBinaryTag skillInfo, CompoundBinaryTag info, OptionalDouble volume, int minDistanceStep, int maxDistanceStep)
      Rejects a null owner, then normalizes every other field as the class javadoc describes.
    • PersistedPet

      @Deprecated(since="4.1.0") public PersistedPet(UUID uuid, MyPetPlayer owner, PetType petType, String petName, String worldGroup, double exp, double health, double saturation, int respawnTime, boolean wantsToRespawn, long lastUsed, Skilltree skilltree, CompoundBinaryTag skillInfo, CompoundBinaryTag info)
      Deprecated.
      use builder(MyPetPlayer) or the canonical constructor.
      Pre-4.1.0 constructor, kept so addons built against the 14-component record keep linking. The pet inherits its owner's volume and both distance steps start on PetDistanceMath.DEFAULT_STEP.
      Parameters:
      uuid - the pet's persistent id; generated when absent
      owner - the owning player; must not be null
      petType - the species; defaults to Wolf when absent
      petName - the raw name in MiniMessage form; empty when absent
      worldGroup - the world group the pet belongs to; empty when absent
      exp - accumulated experience
      health - current health in half-hearts
      saturation - hunger level, clamped to 1..100
      respawnTime - seconds left on the respawn timer; 0 when alive
      wantsToRespawn - whether the pet returns on the owner's next login
      lastUsed - epoch milliseconds of the pet's last activity
      skilltree - the assigned skilltree, or null when none is set
      skillInfo - per-skill persisted state; empty when absent
      info - addon-owned persisted state; empty when absent
  • Method Details

    • getUUID

      public UUID getUUID()
      Description copied from interface: StoredPet
      Globally unique identifier for this pet instance (persisted).
      Specified by:
      getUUID in interface StoredPet
      Returns:
      this pet's persistent unique id
    • getOwner

      public MyPetPlayer getOwner()
      Description copied from interface: StoredPet
      The player who owns this pet.
      Specified by:
      getOwner in interface StoredPet
      Returns:
      the pet's owner
    • getPetType

      public PetType getPetType()
      Description copied from interface: StoredPet
      The mob type this pet represents (e.g., Wolf, Creeper).
      Specified by:
      getPetType in interface StoredPet
      Returns:
      the species this pet is
    • getPetName

      public String getPetName()
      Description copied from interface: StoredPet
      Raw pet name in MiniMessage format.
      Specified by:
      getPetName in interface StoredPet
      Returns:
      the raw name, in MiniMessage form
    • getWorldGroup

      public String getWorldGroup()
      Description copied from interface: StoredPet
      The world-group this pet belongs to (multi-world isolation).
      Specified by:
      getWorldGroup in interface StoredPet
      Returns:
      the world group this pet belongs to
    • getExp

      public double getExp()
      Description copied from interface: StoredPet
      Raw accumulated experience points.
      Specified by:
      getExp in interface StoredPet
      Returns:
      the raw accumulated experience
    • getHealth

      public double getHealth()
      Description copied from interface: StoredPet
      Current health (half-hearts). Zero when dead.
      Specified by:
      getHealth in interface StoredPet
      Returns:
      current health in half-hearts; 0 when dead
    • getSaturation

      public double getSaturation()
      Description copied from interface: StoredPet
      Hunger level (1–100). Drains over time; restored by feeding.
      Specified by:
      getSaturation in interface StoredPet
      Returns:
      the hunger level, from 1 to 100
    • getRespawnTime

      public int getRespawnTime()
      Description copied from interface: StoredPet
      Seconds remaining on the respawn timer. Zero when alive.
      Specified by:
      getRespawnTime in interface StoredPet
      Returns:
      seconds left on the respawn timer; 0 when alive
    • getLastUsed

      public long getLastUsed()
      Description copied from interface: StoredPet
      Epoch millis of the last time this pet was active in the world.
      Specified by:
      getLastUsed in interface StoredPet
      Returns:
      epoch milliseconds of the pet's last activity
    • getSkilltree

      public Skilltree getSkilltree()
      Description copied from interface: StoredPet
      The assigned skilltree, or null if none is set.
      Specified by:
      getSkilltree in interface StoredPet
      Returns:
      the assigned skilltree, or null if none is set
    • getVolume

      public OptionalDouble getVolume()
      Description copied from interface: StoredPet
      This pet's sound-volume override.
      Specified by:
      getVolume in interface StoredPet
      Returns:
      the override in [0, 1], or empty when this pet inherits its owner's setting
    • getMinDistanceStep

      public int getMinDistanceStep()
      Description copied from interface: StoredPet
      Personal-space scale, a step from 1 (very close) to 5 (very far). The block value derives from the pet's hitbox width; see PetDistanceMath.
      Specified by:
      getMinDistanceStep in interface StoredPet
      Returns:
      the min distance step, 1..5
    • getMaxDistanceStep

      public int getMaxDistanceStep()
      Description copied from interface: StoredPet
      Follow-distance scale, a step from 1 (very close) to 5 (very far). The block value derives from the pet's hitbox width; see PetDistanceMath.
      Specified by:
      getMaxDistanceStep in interface StoredPet
      Returns:
      the max distance step, 1..5
    • withUuid

      public PersistedPet withUuid(UUID v)
      Returns a copy with the pet's persistent id replaced and every other field carried over. Single-field updaters — each returns a new PersistedPet with the named field changed and all other fields copied verbatim.
      Parameters:
      v - the new value
      Returns:
      a new instance; this one is unchanged
    • withOwner

      public PersistedPet withOwner(MyPetPlayer v)
      Returns a copy with the owning player replaced and every other field carried over.
      Parameters:
      v - the new value
      Returns:
      a new instance; this one is unchanged
    • withPetType

      public PersistedPet withPetType(PetType v)
      Returns a copy with the species replaced and every other field carried over.
      Parameters:
      v - the new value
      Returns:
      a new instance; this one is unchanged
    • withPetName

      public PersistedPet withPetName(String v)
      Returns a copy with the raw name, in MiniMessage form replaced and every other field carried over.
      Parameters:
      v - the new value
      Returns:
      a new instance; this one is unchanged
    • withWorldGroup

      public PersistedPet withWorldGroup(String v)
      Returns a copy with the world group replaced and every other field carried over.
      Parameters:
      v - the new value
      Returns:
      a new instance; this one is unchanged
    • withExp

      public PersistedPet withExp(double v)
      Returns a copy with the accumulated experience replaced and every other field carried over.
      Parameters:
      v - the new value
      Returns:
      a new instance; this one is unchanged
    • withHealth

      public PersistedPet withHealth(double v)
      Returns a copy with the current health replaced and every other field carried over.
      Parameters:
      v - the new value
      Returns:
      a new instance; this one is unchanged
    • withSaturation

      public PersistedPet withSaturation(double v)
      Returns this unchanged (with a logged warning) when v is NaN or Infinite, preserving the prior value rather than coercing — silently substituting a default would mask data corruption.
      Parameters:
      v - the new saturation
      Returns:
      a new instance, or this when v is not a finite number
    • withRespawnTime

      public PersistedPet withRespawnTime(int v)
      Returns a copy with the respawn timer, in seconds replaced and every other field carried over.
      Parameters:
      v - the new value
      Returns:
      a new instance; this one is unchanged
    • withWantsToRespawn

      public PersistedPet withWantsToRespawn(boolean v)
      Returns a copy with whether the pet returns on the owner's next login replaced and every other field carried over.
      Parameters:
      v - the new value
      Returns:
      a new instance; this one is unchanged
    • withLastUsed

      public PersistedPet withLastUsed(long v)
      Returns a copy with the last-activity timestamp replaced and every other field carried over.
      Parameters:
      v - the new value
      Returns:
      a new instance; this one is unchanged
    • withSkilltree

      public PersistedPet withSkilltree(Skilltree v)
      Returns a copy with the assigned skilltree replaced and every other field carried over.
      Parameters:
      v - the new value
      Returns:
      a new instance; this one is unchanged
    • withSkillInfo

      public PersistedPet withSkillInfo(CompoundBinaryTag v)
      Returns a copy with the per-skill persisted state replaced and every other field carried over.
      Parameters:
      v - the new value
      Returns:
      a new instance; this one is unchanged
    • withVolume

      public PersistedPet withVolume(OptionalDouble v)
      Returns a copy with the sound-volume override replaced and every other field carried over.
      Parameters:
      v - the new override in [0, 1], or empty to inherit the owner's setting
      Returns:
      a new instance; this one is unchanged
    • withSkills

      public PersistedPet withSkills(Collection<Skill> skills)
      Merges per-skill NBT into the existing skillInfo, preserving any keys not produced by the active skills collection so removing a skill from the live tree does not erase its persisted state.
      Parameters:
      skills - the live skills whose state to fold in
      Returns:
      a new instance carrying the merged skill state
    • withMinDistanceStep

      public PersistedPet withMinDistanceStep(int v)
      Returns a copy with the personal-space step replaced and every other field carried over.
      Parameters:
      v - the new value
      Returns:
      a new instance; this one is unchanged
    • withMaxDistanceStep

      public PersistedPet withMaxDistanceStep(int v)
      Returns a copy with the follow-distance step replaced and every other field carried over.
      Parameters:
      v - the new value
      Returns:
      a new instance; this one is unchanged
    • builder

      public static PersistedPet.Builder builder(MyPetPlayer owner)
      Starts building a pet for the given owner.
      Parameters:
      owner - the owning player; must not be null
      Returns:
      a builder seeded with defaults
    • toBuilder

      public PersistedPet.Builder toBuilder()
      Starts building from this pet's current values.
      Returns:
      a builder pre-filled from this instance
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • uuid

      public UUID uuid()
      Returns the value of the uuid record component.
      Returns:
      the value of the uuid record component
    • owner

      public MyPetPlayer owner()
      Returns the value of the owner record component.
      Returns:
      the value of the owner record component
    • petType

      public PetType petType()
      Returns the value of the petType record component.
      Returns:
      the value of the petType record component
    • petName

      public String petName()
      Returns the value of the petName record component.
      Returns:
      the value of the petName record component
    • worldGroup

      public String worldGroup()
      Returns the value of the worldGroup record component.
      Returns:
      the value of the worldGroup record component
    • exp

      public double exp()
      Returns the value of the exp record component.
      Returns:
      the value of the exp record component
    • health

      public double health()
      Returns the value of the health record component.
      Returns:
      the value of the health record component
    • saturation

      public double saturation()
      Returns the value of the saturation record component.
      Returns:
      the value of the saturation record component
    • respawnTime

      public int respawnTime()
      Returns the value of the respawnTime record component.
      Returns:
      the value of the respawnTime record component
    • wantsToRespawn

      public boolean wantsToRespawn()
      Returns the value of the wantsToRespawn record component.
      Specified by:
      wantsToRespawn in interface StoredPet
      Returns:
      the value of the wantsToRespawn record component
    • lastUsed

      public long lastUsed()
      Returns the value of the lastUsed record component.
      Returns:
      the value of the lastUsed record component
    • skilltree

      public Skilltree skilltree()
      Returns the value of the skilltree record component.
      Returns:
      the value of the skilltree record component
    • skillInfo

      public CompoundBinaryTag skillInfo()
      Returns the value of the skillInfo record component.
      Returns:
      the value of the skillInfo record component
    • info

      public CompoundBinaryTag info()
      Returns the value of the info record component.
      Returns:
      the value of the info record component
    • volume

      public OptionalDouble volume()
      Returns the value of the volume record component.
      Returns:
      the value of the volume record component
    • minDistanceStep

      public int minDistanceStep()
      Returns the value of the minDistanceStep record component.
      Returns:
      the value of the minDistanceStep record component
    • maxDistanceStep

      public int maxDistanceStep()
      Returns the value of the maxDistanceStep record component.
      Returns:
      the value of the maxDistanceStep record component