From 8043115be517f8294c81d71594461e003f1adf80 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Mon, 6 May 2024 17:31:07 +0200 Subject: Backend: better error detection in enchant parser (#1634) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../features/misc/items/enchants/EnchantParser.kt | 26 +++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt index c8d24092f..593e844d4 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt @@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.LorenzToolTipEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.mixins.hooks.GuiChatHook +import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ConditionalUtils import at.hannibal2.skyhanni.utils.ItemCategory import at.hannibal2.skyhanni.utils.ItemUtils.getItemCategoryOrNull @@ -174,7 +175,18 @@ object EnchantParser { } // Remove enchantment lines so we can insert ours - loreList.subList(startEnchant, endEnchant + 1).clear() + try { + loreList.subList(startEnchant, endEnchant + 1).clear() + } catch (e: IndexOutOfBoundsException) { + ErrorManager.logErrorWithData( + e, + "Error parsing enchantment info from item", + "loreList" to loreList, + "startEnchant" to startEnchant, + "endEnchant" to endEnchant, + ) + return + } val insertEnchants: MutableList = mutableListOf() @@ -256,10 +268,10 @@ object EnchantParser { // Normal is leaving the formatting as Hypixel provides it if (config.format.get() == EnchantParsingConfig.EnchantFormat.NORMAL) { normalFormatting(insertEnchants) - // Compressed is always forcing 3 enchants per line, except when there is stacking enchant progress visible + // Compressed is always forcing 3 enchants per line, except when there is stacking enchant progress visible } else if (config.format.get() == EnchantParsingConfig.EnchantFormat.COMPRESSED && !shouldBeSingleColumn) { compressedFormatting(insertEnchants) - // Stacked is always forcing 1 enchant per line + // Stacked is always forcing 1 enchant per line } else { stackedFormatting(insertEnchants) } @@ -320,7 +332,11 @@ object EnchantParser { } } - private fun finishFormatting(insertEnchants: MutableList, builder: StringBuilder, commaFormat: CommaFormat) { + private fun finishFormatting( + insertEnchants: MutableList, + builder: StringBuilder, + commaFormat: CommaFormat, + ) { if (builder.isNotEmpty()) insertEnchants.add(builder.toString()) // Check if there is a trailing space (therefore also a comma) and remove the last 2 chars @@ -371,7 +387,7 @@ object EnchantParser { return if (removeGrayEnchants) -1 else lastGrayEnchant } - private fun itemIsBook() : Boolean { + private fun itemIsBook(): Boolean { return currentItem?.getItemCategoryOrNull() == ItemCategory.ENCHANTED_BOOK } -- cgit