diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-08 12:39:08 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-08 12:39:08 +0200 |
commit | 50710bea90daa9ef159257d5d04e5e9b8ce9ad82 (patch) | |
tree | b404cfcd3d438fc2273920f0db44a422b6681ed5 /src/main/java/at/hannibal2/skyhanni | |
parent | 22b8af50f2cea3c38396726ca45a20933c585089 (diff) | |
download | skyhanni-50710bea90daa9ef159257d5d04e5e9b8ce9ad82.tar.gz skyhanni-50710bea90daa9ef159257d5d04e5e9b8ce9ad82.tar.bz2 skyhanni-50710bea90daa9ef159257d5d04e5e9b8ce9ad82.zip |
Added pet rarity support
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 17 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt | 5 |
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 |