aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt17
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt5
2 files changed, 18 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
index 1433961d2..aee09514f 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
@@ -155,6 +155,10 @@ object ItemUtils {
fun ItemStack.getItemRarity() = getItemRarityOrNull() ?: error("item rarity not detected for item '$name'")
fun ItemStack.getItemRarityOrNull(): LorenzRarity? {
+ if (isPet(cleanName())) {
+ return getPetRarity(this)
+ }
+
return when (this.getLore().lastOrNull()?.take(4)) {
"§f§l" -> LorenzRarity.COMMON
"§a§l" -> LorenzRarity.UNCOMMON
@@ -235,10 +239,15 @@ object ItemUtils {
return getItemStack().nameWithEnchantment ?: error("Could not find item name for $this")
}
+ // TODO: Replace entirely some day
fun getPetRarityOld(petStack: ItemStack?): Int {
- val petInternalName = petStack?.getInternalName_old()
- if (petInternalName == "NONE" || petInternalName == null) return -1
- val split = petInternalName.split(";")
- return split.last().toInt()
+ val rarity = petStack?.getItemRarityOrNull() ?: return -1
+
+ return rarity.id
+ }
+
+ private fun getPetRarity(pet: ItemStack): LorenzRarity? {
+ val rarityId = pet.getInternalName().asString().split(";").last().toInt()
+ return LorenzRarity.getById(rarityId)
}
} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt
index a6f6f6f06..f21d5e32e 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.utils
+// TODO: replace id with ordinal
enum class LorenzRarity(val color: LorenzColor, val id: Int) {
COMMON(LorenzColor.WHITE, 0),
UNCOMMON(LorenzColor.GREEN, 1),
@@ -13,4 +14,8 @@ enum class LorenzRarity(val color: LorenzColor, val id: Int) {
SPECIAL(LorenzColor.RED, 8),
;
+ companion object {
+ fun getById(id: Int) = entries.firstOrNull { it.id == id }
+ }
+
} \ No newline at end of file