Skip to content

Commit

Permalink
fix equals and hashcode, make petItem nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
martimavocado committed Oct 16, 2024
1 parent 971e6c6 commit d31fae6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
18 changes: 2 additions & 16 deletions src/main/java/at/hannibal2/skyhanni/data/PetAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ object PetAPI {
NEUInternalName.NONE,
"",
LorenzRarity.getByName(petInfo.tier) ?: LorenzRarity.ULTIMATE,
petInfo.heldItem?.asInternalName() ?: NEUInternalName.NONE,
petInfo.heldItem?.asInternalName(),
0,
petInfo.exp,
""
Expand All @@ -466,7 +466,7 @@ object PetAPI {
petNameToInternalName(name, rarity),
name,
rarity,
NEUInternalName.NONE,
null,
level,
0.0,
skin,
Expand Down Expand Up @@ -592,20 +592,6 @@ object PetAPI {
private fun petNameToInternalName(petName: String, rarity: LorenzRarity): NEUInternalName {
return "${petNameToFakeInternalName(petName)};${rarity.id}".asInternalName()
}
override fun equals(other: Any?): Boolean {
if (other !is PetData) return false
return this.pet?.internalName == other.internalName &&
this.pet?.cleanName == other.cleanName &&
this.pet?.rarity == other.rarity &&
this.pet?.petItem == other.petItem &&
this.pet?.level == other.level &&
this.pet?.rawPetName == other.rawPetName
}
override fun hashCode(): Int {
return pet?.hashCode() ?: 0
}
}
data class PetNBT(
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/data/PetData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,27 @@ data class PetData(
val internalName: NEUInternalName,
val cleanName: String,
val rarity: LorenzRarity,
val petItem: NEUInternalName,
val petItem: NEUInternalName?,
val level: Int,
val xp: Double,
val rawPetName: String,
)
) {
override fun equals(other: Any?): Boolean {
if (other !is PetData) return false
return this.internalName == other.internalName &&
this.cleanName == other.cleanName &&
this.rarity == other.rarity &&
this.petItem == other.petItem &&
this.level == other.level &&
this.rawPetName == other.rawPetName
}

override fun hashCode(): Int {
var result = cleanName.hashCode()
result = 31 * result + rarity.hashCode()
result = 31 * result + (petItem?.hashCode() ?: 0)
result = 31 * result + level
result = 31 * result + rawPetName.hashCode()
return result
}
}

0 comments on commit d31fae6

Please sign in to comment.