diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-01 01:59:30 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-01 01:59:30 +0200 |
commit | 07a16dae17b80b0e489c812d80f6e92745db80ac (patch) | |
tree | 5e744e938013a59d719bbe0ade0f5565e8abf483 /src/main/java | |
parent | 1bad17906dc6f5f1f65b48300404dec4c3b67043 (diff) | |
download | skyhanni-07a16dae17b80b0e489c812d80f6e92745db80ac.tar.gz skyhanni-07a16dae17b80b0e489c812d80f6e92745db80ac.tar.bz2 skyhanni-07a16dae17b80b0e489c812d80f6e92745db80ac.zip |
Fixed Anita shop delicate enchant
Diffstat (limited to 'src/main/java')
3 files changed, 22 insertions, 11 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt index fa6500bcb..0f51e65aa 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt @@ -42,12 +42,18 @@ class AnitaMedalProfit { fun onInventoryOpen(event: InventoryOpenEvent) { if (!config.anitaMedalProfitEnabled) return if (event.inventoryName != "Anita") return + if (GardenVisitorFeatures.inVisitorInventory) return inInventory = true val table = mutableMapOf<Pair<String, String>, Pair<Double, String>>() for ((_, item) in event.inventoryItems) { - readItem(item, table) + try { + readItem(item, table) + } catch (e: Throwable) { + LorenzUtils.error("Error in AnitaMedalProfit while reading item '$item'") + e.printStackTrace() + } } val newList = mutableListOf<List<Any>>() @@ -59,6 +65,10 @@ class AnitaMedalProfit { private fun readItem(item: ItemStack, table: MutableMap<Pair<String, String>, Pair<Double, String>>) { var itemName = item.name ?: return if (itemName == " ") return + if (itemName == "§cClose") return + if (itemName == "§eUnique Gold Medals") return + if (itemName == "§aMedal Trades") return + if (itemName.endsWith("Enchanted Book")) { itemName = item.getLore()[0] } @@ -69,11 +79,9 @@ class AnitaMedalProfit { val (name, amount) = ItemUtils.readItemAmount(itemName) if (name == null) return - val internalName = try { - NEUItems.getInternalName(name) - } catch (e: Exception) { - // TODO make a better alternative - item.getInternalName() + var internalName = NEUItems.getInternalNameOrNull(name) + if (internalName == null) { + internalName = item.getInternalName() } val itemPrice = NEUItems.getPrice(internalName) * amount diff --git a/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt b/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt index 02feac91c..45748339c 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt @@ -92,7 +92,7 @@ class LorenzTest { try { val internalName = NEUItems.getInternalName(itemName) list.add(NEUItems.getItemStack(internalName)) - } catch (e: Exception) { + } catch (e: Error) { LorenzUtils.debug("itemName '$itemName' is invalid for visitor '$name'") errors++ } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 563e8976e..85dc8816c 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -21,18 +21,21 @@ object NEUItems { private val recipesCache = mutableMapOf<String, Set<NeuRecipe>>() fun getInternalName(itemName: String): String { + return getInternalNameOrNull(itemName) ?: throw Error("getInternalName is null for '$itemName'") + } + + fun getInternalNameOrNull(itemName: String): String? { if (itemNameCache.containsKey(itemName)) { return itemNameCache[itemName]!! } - var internalName = ItemResolutionQuery.findInternalNameByDisplayName(itemName, false) + var internalName = ItemResolutionQuery.findInternalNameByDisplayName(itemName, false) ?: return null + // This fixes a NEU bug with §9Hay Bale (cosmetic item) // TODO remove workaround when this is fixed in neu if (internalName == "HAY_BALE") { internalName = "HAY_BLOCK" } - if (internalName == null) { - throw Error("getInternalName is null for '$itemName'") - } + itemNameCache[itemName] = internalName return internalName } |