diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-12 10:22:02 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-12 10:22:02 +0100 |
commit | 3955895537e2e5f18036b671d0fb692dcbb1ae2b (patch) | |
tree | c3965de7f766a471e5017c9e6f7c90503fde21a6 /src/main | |
parent | 669ea76011e12b8befb853b5e9c9e8070bc504de (diff) | |
download | skyhanni-3955895537e2e5f18036b671d0fb692dcbb1ae2b.tar.gz skyhanni-3955895537e2e5f18036b671d0fb692dcbb1ae2b.tar.bz2 skyhanni-3955895537e2e5f18036b671d0fb692dcbb1ae2b.zip |
added debug information for PetExpTooltip crash
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt | 64 |
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" + ) } } |