aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-09-09 10:48:30 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-09-09 10:48:30 +0200
commitd4ef47dc97cf8c89fe9182ca2e5cd1ef04bd09d2 (patch)
treea655c16e7fc8a677fd42420efdb510e23bc386b3 /src
parent3eccd5fdc94c8ca5afa9da367cbefba54e0a457a (diff)
downloadskyhanni-d4ef47dc97cf8c89fe9182ca2e5cd1ef04bd09d2.tar.gz
skyhanni-d4ef47dc97cf8c89fe9182ca2e5cd1ef04bd09d2.tar.bz2
skyhanni-d4ef47dc97cf8c89fe9182ca2e5cd1ef04bd09d2.zip
fixed crash when item rarity can not be detected in ah browser
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt30
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt27
3 files changed, 56 insertions, 7 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt
index 5abc467a1..53e58e4bf 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt
@@ -2,7 +2,7 @@ package at.hannibal2.skyhanni.features.misc
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.utils.*
-import at.hannibal2.skyhanni.utils.ItemUtils.getItemRarity
+import at.hannibal2.skyhanni.utils.ItemUtils.getItemRarityOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils.indexOfFirst
import at.hannibal2.skyhanni.utils.LorenzUtils.round
@@ -42,8 +42,8 @@ class PetExpTooltip {
event.toolTip.add(index, "§7Total experience: §e${NumberUtil.format(petExperience)}")
} else {
val progressBar = StringUtils.progressBar(percentage)
- val isBelowLEgendary = itemStack.getItemRarity() < LorenzRarity.LEGENDARY
- val addLegendaryColor = if (isBelowLEgendary) "§6" else ""
+ val isBelowLegendary = itemStack.getItemRarityOrNull()?.let { it < LorenzRarity.LEGENDARY } ?: false
+ val addLegendaryColor = if (isBelowLegendary) "§6" else ""
event.toolTip.add(index, "$progressBar §e${petExperience.addSeparators()}§6/§e${NumberUtil.format(maxXp)}")
event.toolTip.add(index, "§7Progress to ${addLegendaryColor}Level $maxLevel: §e$percentageFormat")
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
index aee09514f..25d5f9df4 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.utils
+import at.hannibal2.skyhanni.test.command.CopyErrorCommand
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRecombobulated
@@ -159,7 +160,16 @@ object ItemUtils {
return getPetRarity(this)
}
- return when (this.getLore().lastOrNull()?.take(4)) {
+ val lore = getLore()
+ var lastLine = lore.lastOrNull() ?: return null
+ if (lastLine == "§eClick to inspect!") {
+ // Assuming inside ah browser
+ val index = lore.indexOfFirst { it.startsWith("§7Seller: ") } - 2
+ if (index > 0) {
+ lastLine = lore[index]
+ }
+ }
+ return when (lastLine.take(4)) {
"§f§l" -> LorenzRarity.COMMON
"§a§l" -> LorenzRarity.UNCOMMON
"§9§l" -> LorenzRarity.RARE
@@ -169,7 +179,13 @@ object ItemUtils {
"§b§l" -> LorenzRarity.DIVINE
"§4§l" -> LorenzRarity.SUPREME
"§c§l" -> LorenzRarity.SPECIAL
- else -> null
+ else -> {
+ CopyErrorCommand.logErrorState(
+ "Could not read rarity for item $name",
+ "getItemRarityOrNull not found for: ${getInternalName()}, name:'$name', lastLine:'$lastLine'"
+ )
+ return null
+ }
}
}
@@ -248,6 +264,14 @@ object ItemUtils {
private fun getPetRarity(pet: ItemStack): LorenzRarity? {
val rarityId = pet.getInternalName().asString().split(";").last().toInt()
- return LorenzRarity.getById(rarityId)
+ val rarity = LorenzRarity.getById(rarityId)
+ val name = pet.name
+ if (rarity == null) {
+ CopyErrorCommand.logErrorState(
+ "Could not read rarity for pet $name",
+ "getPetRarity not found for: ${pet.getInternalName()}, name:'$name'"
+ )
+ }
+ return rarity
}
} \ 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 f21d5e32e..4af8f7e2f 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt
@@ -1,5 +1,7 @@
package at.hannibal2.skyhanni.utils
+import at.hannibal2.skyhanni.test.command.CopyErrorCommand
+
// TODO: replace id with ordinal
enum class LorenzRarity(val color: LorenzColor, val id: Int) {
@@ -12,10 +14,33 @@ enum class LorenzRarity(val color: LorenzColor, val id: Int) {
DIVINE(LorenzColor.AQUA, 6),
SUPREME(LorenzColor.DARK_RED, 7),
SPECIAL(LorenzColor.RED, 8),
+ VERY_SPECIAL(LorenzColor.RED, 9),
;
+ fun oneBelow(logError: Boolean = true): LorenzRarity? {
+ val rarityBelow = getById(ordinal - 1)
+ if (rarityBelow == null && logError) {
+ CopyErrorCommand.logErrorState(
+ "Problem with item rarity detected.",
+ "Trying to get an item rarity below common"
+ )
+ }
+ return rarityBelow
+ }
+
+ fun oneAbove(logError: Boolean = true): LorenzRarity? {
+ val rarityBelow = getById(ordinal + 1)
+ if (rarityBelow == null && logError) {
+ CopyErrorCommand.logErrorState(
+ "Problem with item rarity detected.",
+ "Trying to get an item rarity above special"
+ )
+ }
+ return rarityBelow
+ }
+
companion object {
- fun getById(id: Int) = entries.firstOrNull { it.id == id }
+ fun getById(id: Int) = entries.firstOrNull { it.ordinal == id }
}
} \ No newline at end of file