From cbdaf0bccd95ba0c92d4d0994ae4c8094ca0da15 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 5 Sep 2022 17:38:41 +0100 Subject: [PATCH] Fixed very specific anvil edge case --- .../willfp/ecoenchants/mechanics/AnvilSupport.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/AnvilSupport.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/AnvilSupport.kt index 33b10b66..3610b438 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/AnvilSupport.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/AnvilSupport.kt @@ -17,7 +17,6 @@ import org.bukkit.event.inventory.PrepareAnvilEvent import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.Damageable import org.bukkit.inventory.meta.EnchantmentStorageMeta -import org.jetbrains.annotations.NotNull import java.util.* import kotlin.math.abs import kotlin.math.max @@ -90,15 +89,24 @@ class AnvilSupport( val oldLeft = event.inventory.getItem(0) + if (result == FAIL) { + return@run + } + if (oldLeft == null || oldLeft.type != outItem.type) { return@run } - if (result == FAIL || left == old) { + if (left == old) { return@run } - val cost = oldCost + price + var cost = oldCost + price + + // Unbelievably specific edge case + if (oldCost == -price) { + cost = price + } // Cost could be less than zero at times, so I include that here. if (cost <= 0) {