aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-05-06 17:31:07 +0200
committerGitHub <noreply@github.com>2024-05-06 17:31:07 +0200
commit8043115be517f8294c81d71594461e003f1adf80 (patch)
tree72c594bec7cd992c30d9b95c5c6a513bb5067b04 /src/main
parent026bd1c14fb5ee90ba8b828b843d1a048dc9c838 (diff)
downloadskyhanni-8043115be517f8294c81d71594461e003f1adf80.tar.gz
skyhanni-8043115be517f8294c81d71594461e003f1adf80.tar.bz2
skyhanni-8043115be517f8294c81d71594461e003f1adf80.zip
Backend: better error detection in enchant parser (#1634)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt26
1 files changed, 21 insertions, 5 deletions
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<String> = 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<String>, builder: StringBuilder, commaFormat: CommaFormat) {
+ private fun finishFormatting(
+ insertEnchants: MutableList<String>,
+ 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
}