Package de.Keyle.MyPet.api.entity
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 absentowner- the owning player; must not benullpetType- the species; defaults to Wolf when absentpetName- the raw name in MiniMessage form; empty when absentworldGroup- the world group the pet belongs to; empty when absentexp- accumulated experiencehealth- current health in half-heartssaturation- hunger level, clamped to 1..100respawnTime- seconds left on the respawn timer; 0 when alivewantsToRespawn- whether the pet returns on the owner's next loginlastUsed- epoch milliseconds of the pet's last activityskilltree- the assigned skilltree, ornullwhen none is setskillInfo- per-skill persisted state; empty when absentinfo- addon-owned persisted state; empty when absentvolume- the pet's sound-volume override in [0, 1]; empty when the pet inherits its owner's settingminDistanceStep- 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classStep-by-step construction of aPersistedPet, for callers setting more than one field. -
Constructor Summary
ConstructorsConstructorDescriptionPersistedPet(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.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. -
Method Summary
Modifier and TypeMethodDescriptionstatic PersistedPet.Builderbuilder(MyPetPlayer owner) Starts building a pet for the given owner.final booleanIndicates whether some other object is "equal to" this one.doubleexp()Returns the value of theexprecord component.doublegetExp()Raw accumulated experience points.doubleCurrent health (half-hearts).longEpoch millis of the last time this pet was active in the world.intFollow-distance scale, a step from1(very close) to5(very far).intPersonal-space scale, a step from1(very close) to5(very far).getOwner()The player who owns this pet.Raw pet name in MiniMessage format.The mob type this pet represents (e.g., Wolf, Creeper).intSeconds remaining on the respawn timer.doubleHunger level (1–100).The assigned skilltree, ornullif none is set.getUUID()Globally unique identifier for this pet instance (persisted).This pet's sound-volume override.The world-group this pet belongs to (multi-world isolation).final inthashCode()Returns a hash code value for this object.doublehealth()Returns the value of thehealthrecord component.info()Returns the value of theinforecord component.longlastUsed()Returns the value of thelastUsedrecord component.intReturns the value of themaxDistanceSteprecord component.intReturns the value of theminDistanceSteprecord component.owner()Returns the value of theownerrecord component.petName()Returns the value of thepetNamerecord component.petType()Returns the value of thepetTyperecord component.intReturns the value of therespawnTimerecord component.doubleReturns the value of thesaturationrecord component.Returns the value of theskillInforecord component.Returns the value of theskilltreerecord component.Starts building from this pet's current values.final StringtoString()Returns a string representation of this record class.uuid()Returns the value of theuuidrecord component.volume()Returns the value of thevolumerecord component.booleanReturns the value of thewantsToRespawnrecord component.withExp(double v) Returns a copy with the accumulated experience replaced and every other field carried over.withHealth(double v) Returns a copy with the current health replaced and every other field carried over.withLastUsed(long v) Returns a copy with the last-activity timestamp replaced and every other field carried over.withMaxDistanceStep(int v) Returns a copy with the follow-distance step replaced and every other field carried over.withMinDistanceStep(int v) Returns a copy with the personal-space step replaced and every other field carried over.Returns a copy with the owning player replaced and every other field carried over.Returns a copy with the raw name, in MiniMessage form replaced and every other field carried over.Returns a copy with the species replaced and every other field carried over.withRespawnTime(int v) Returns a copy with the respawn timer, in seconds replaced and every other field carried over.withSaturation(double v) Returnsthisunchanged (with a logged warning) whenvisNaNorInfinite, preserving the prior value rather than coercing — silently substituting a default would mask data corruption.Returns a copy with the per-skill persisted state replaced and every other field carried over.withSkills(Collection<Skill> skills) Merges per-skill NBT into the existingskillInfo, preserving any keys not produced by the activeskillscollection so removing a skill from the live tree does not erase its persisted state.Returns a copy with the assigned skilltree replaced and every other field carried over.Returns a copy with the pet's persistent id replaced and every other field carried over.Returns a copy with the sound-volume override replaced and every other field carried over.withWantsToRespawn(boolean v) Returns a copy with whether the pet returns on the owner's next login replaced and every other field carried over.Returns a copy with the world group replaced and every other field carried over.Returns the value of theworldGrouprecord component.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface de.Keyle.MyPet.api.entity.StoredPet
getDisplayName, getLevel, skillState
-
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.usebuilder(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 onPetDistanceMath.DEFAULT_STEP.- Parameters:
uuid- the pet's persistent id; generated when absentowner- the owning player; must not benullpetType- the species; defaults to Wolf when absentpetName- the raw name in MiniMessage form; empty when absentworldGroup- the world group the pet belongs to; empty when absentexp- accumulated experiencehealth- current health in half-heartssaturation- hunger level, clamped to 1..100respawnTime- seconds left on the respawn timer; 0 when alivewantsToRespawn- whether the pet returns on the owner's next loginlastUsed- epoch milliseconds of the pet's last activityskilltree- the assigned skilltree, ornullwhen none is setskillInfo- per-skill persisted state; empty when absentinfo- addon-owned persisted state; empty when absent
-
-
Method Details
-
getUUID
Description copied from interface:StoredPetGlobally unique identifier for this pet instance (persisted). -
getOwner
Description copied from interface:StoredPetThe player who owns this pet. -
getPetType
Description copied from interface:StoredPetThe mob type this pet represents (e.g., Wolf, Creeper).- Specified by:
getPetTypein interfaceStoredPet- Returns:
- the species this pet is
-
getPetName
Description copied from interface:StoredPetRaw pet name in MiniMessage format.- Specified by:
getPetNamein interfaceStoredPet- Returns:
- the raw name, in MiniMessage form
-
getWorldGroup
Description copied from interface:StoredPetThe world-group this pet belongs to (multi-world isolation).- Specified by:
getWorldGroupin interfaceStoredPet- Returns:
- the world group this pet belongs to
-
getExp
public double getExp()Description copied from interface:StoredPetRaw accumulated experience points. -
getHealth
public double getHealth()Description copied from interface:StoredPetCurrent health (half-hearts). Zero when dead. -
getSaturation
public double getSaturation()Description copied from interface:StoredPetHunger level (1–100). Drains over time; restored by feeding.- Specified by:
getSaturationin interfaceStoredPet- Returns:
- the hunger level, from 1 to 100
-
getRespawnTime
public int getRespawnTime()Description copied from interface:StoredPetSeconds remaining on the respawn timer. Zero when alive.- Specified by:
getRespawnTimein interfaceStoredPet- Returns:
- seconds left on the respawn timer;
0when alive
-
getLastUsed
public long getLastUsed()Description copied from interface:StoredPetEpoch millis of the last time this pet was active in the world.- Specified by:
getLastUsedin interfaceStoredPet- Returns:
- epoch milliseconds of the pet's last activity
-
getSkilltree
Description copied from interface:StoredPetThe assigned skilltree, ornullif none is set.- Specified by:
getSkilltreein interfaceStoredPet- Returns:
- the assigned skilltree, or
nullif none is set
-
getVolume
Description copied from interface:StoredPetThis pet's sound-volume override. -
getMinDistanceStep
public int getMinDistanceStep()Description copied from interface:StoredPetPersonal-space scale, a step from1(very close) to5(very far). The block value derives from the pet's hitbox width; seePetDistanceMath.- Specified by:
getMinDistanceStepin interfaceStoredPet- Returns:
- the min distance step,
1..5
-
getMaxDistanceStep
public int getMaxDistanceStep()Description copied from interface:StoredPetFollow-distance scale, a step from1(very close) to5(very far). The block value derives from the pet's hitbox width; seePetDistanceMath.- Specified by:
getMaxDistanceStepin interfaceStoredPet- Returns:
- the max distance step,
1..5
-
withUuid
Returns a copy with the pet's persistent id replaced and every other field carried over. Single-field updaters — each returns a newPersistedPetwith the named field changed and all other fields copied verbatim.- Parameters:
v- the new value- Returns:
- a new instance; this one is unchanged
-
withOwner
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
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
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
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
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
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
Returnsthisunchanged (with a logged warning) whenvisNaNorInfinite, 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
thiswhenvis not a finite number
-
withRespawnTime
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
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
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
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
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
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
Merges per-skill NBT into the existingskillInfo, preserving any keys not produced by the activeskillscollection 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
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
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
Starts building a pet for the given owner.- Parameters:
owner- the owning player; must not benull- Returns:
- a builder seeded with defaults
-
toBuilder
Starts building from this pet's current values.- Returns:
- a builder pre-filled from this instance
-
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
uuid
Returns the value of theuuidrecord component.- Returns:
- the value of the
uuidrecord component
-
owner
Returns the value of theownerrecord component.- Returns:
- the value of the
ownerrecord component
-
petType
Returns the value of thepetTyperecord component.- Returns:
- the value of the
petTyperecord component
-
petName
Returns the value of thepetNamerecord component.- Returns:
- the value of the
petNamerecord component
-
worldGroup
Returns the value of theworldGrouprecord component.- Returns:
- the value of the
worldGrouprecord component
-
exp
public double exp()Returns the value of theexprecord component.- Returns:
- the value of the
exprecord component
-
health
public double health()Returns the value of thehealthrecord component.- Returns:
- the value of the
healthrecord component
-
saturation
public double saturation()Returns the value of thesaturationrecord component.- Returns:
- the value of the
saturationrecord component
-
respawnTime
public int respawnTime()Returns the value of therespawnTimerecord component.- Returns:
- the value of the
respawnTimerecord component
-
wantsToRespawn
public boolean wantsToRespawn()Returns the value of thewantsToRespawnrecord component.- Specified by:
wantsToRespawnin interfaceStoredPet- Returns:
- the value of the
wantsToRespawnrecord component
-
lastUsed
public long lastUsed()Returns the value of thelastUsedrecord component.- Returns:
- the value of the
lastUsedrecord component
-
skilltree
Returns the value of theskilltreerecord component.- Returns:
- the value of the
skilltreerecord component
-
skillInfo
Returns the value of theskillInforecord component.- Returns:
- the value of the
skillInforecord component
-
info
Returns the value of theinforecord component.- Returns:
- the value of the
inforecord component
-
volume
Returns the value of thevolumerecord component.- Returns:
- the value of the
volumerecord component
-
minDistanceStep
public int minDistanceStep()Returns the value of theminDistanceSteprecord component.- Returns:
- the value of the
minDistanceSteprecord component
-
maxDistanceStep
public int maxDistanceStep()Returns the value of themaxDistanceSteprecord component.- Returns:
- the value of the
maxDistanceSteprecord component
-
builder(MyPetPlayer)or the canonical constructor.