aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt64
1 files changed, 46 insertions, 18 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 010b2530d..467dad0ff 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,9 @@ package at.hannibal2.skyhanni.features.misc
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
+import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ItemUtils.getItemRarityOrNull
+import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.KeyboardManager
import at.hannibal2.skyhanni.utils.LorenzRarity
@@ -23,6 +25,7 @@ class PetExpTooltip {
private val level100Common = 5_624_785
private val level100Legendary = 25_353_230
private val level200 = 210_255_385
+ private var debugInfoPrinted = false
@SubscribeEvent(priority = EventPriority.LOWEST)
fun onItemTooltipLow(event: ItemTooltipEvent) {
@@ -33,23 +36,44 @@ class PetExpTooltip {
val itemStack = event.itemStack ?: return
val petExperience = itemStack.getPetExp()?.round(1) ?: return
val name = itemStack.name ?: return
-
- val index = findIndex(event.toolTip) ?: return
-
- val (maxLevel, maxXp) = getMaxValues(name, petExperience)
-
- val percentage = petExperience / maxXp
- val percentageFormat = LorenzUtils.formatPercentage(percentage)
-
- event.toolTip.add(index, " ")
- if (percentage >= 1) {
- event.toolTip.add(index, "§7Total experience: §e${NumberUtil.format(petExperience)}")
- } else {
- val progressBar = StringUtils.progressBar(percentage)
- 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")
+ try {
+
+ val index = findIndex(event.toolTip) ?: return
+
+ val (maxLevel, maxXp) = getMaxValues(name, petExperience)
+
+ val percentage = petExperience / maxXp
+ val percentageFormat = LorenzUtils.formatPercentage(percentage)
+
+ event.toolTip.add(index, " ")
+ if (percentage >= 1) {
+ event.toolTip.add(index, "§7Total experience: §e${NumberUtil.format(petExperience)}")
+ } else {
+ val progressBar = StringUtils.progressBar(percentage)
+ 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")
+ }
+ } catch (e: Exception) {
+ if (!debugInfoPrinted) {
+ println(" ")
+ println("PetExpTooltip debug:")
+ println("itemStack: $itemStack")
+ println("itemStack.name: $name")
+ println("petExperience: $petExperience")
+ println("event.toolTip: ${event.toolTip}")
+ println(" ")
+ println("findIndex(event.toolTip): ${findIndex(event.toolTip)}")
+ println(" ")
+ println("itemStack.getLore(): ${itemStack.getLore()}")
+ println(" ")
+ debugInfoPrinted = true
+ }
+ ErrorManager.logError(e, "Could not add pet exp tooltip. Show the console for more info")
}
}
@@ -100,6 +124,10 @@ class PetExpTooltip {
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(3, "misc.petExperienceToolTip.petDisplay", "misc.pets.petExperienceToolTip.petDisplay")
event.move(3, "misc.petExperienceToolTip.showAlways", "misc.pets.petExperienceToolTip.showAlways")
- event.move(3, "misc.petExperienceToolTip.showGoldenDragonEgg", "misc.pets.petExperienceToolTip.showGoldenDragonEgg")
+ event.move(
+ 3,
+ "misc.petExperienceToolTip.showGoldenDragonEgg",
+ "misc.pets.petExperienceToolTip.showGoldenDragonEgg"
+ )
}
}