From da10f0df5f2580dfdb977e7737aec06e93757723 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Thu, 16 Jul 2026 18:26:52 +0200 Subject: [PATCH 1/4] proper stop on legacy check & add env variable to bypass --- src/main/kotlin/io/delilaheve/CustomAnvil.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/io/delilaheve/CustomAnvil.kt b/src/main/kotlin/io/delilaheve/CustomAnvil.kt index 66d812b9..762c8b63 100644 --- a/src/main/kotlin/io/delilaheve/CustomAnvil.kt +++ b/src/main/kotlin/io/delilaheve/CustomAnvil.kt @@ -136,7 +136,7 @@ open class CustomAnvil : JavaPlugin() { override fun onEnable() { instance = this try { - legacyCheck() + if(legacyCheck()) return } catch (e: Exception) { logger.log(Level.SEVERE, "error trying to check for legacy system", e) MetricsUtil.trackError(e) @@ -202,14 +202,15 @@ open class CustomAnvil : JavaPlugin() { } } - private fun legacyCheck() { + private fun legacyCheck(): Boolean { val currentVersion = UpdateUtils.currentMinecraftVersion() if (currentVersion.greaterEqual(Version(1, 21, 0)) - && !DependencyManager.inTesting) { + && !DependencyManager.inTesting + && !"true".equals(System.getenv("CUSTOM_ANVIL_BYPASS_LEGACY_CHECK"), true)) { logger.warning("You are running a Minecraft version above or equal to 1.21.0") logger.warning("Please use CustomAnvil v2 instead if you wish to use the plugin with this version.") Bukkit.getPluginManager().disablePlugin(this) - return + return true } // Disable old plugin name if exist val potentialPlugin = Bukkit.getPluginManager().getPlugin("UnsafeEnchantsPlus") @@ -242,6 +243,7 @@ open class CustomAnvil : JavaPlugin() { logger.warning("An update may be available: $latestVer") } + return false } private fun registerListeners() { From 7b232528f1e0deb37e4d7a97be99516d1905ecaa Mon Sep 17 00:00:00 2001 From: alexcrea Date: Thu, 16 Jul 2026 18:44:23 +0200 Subject: [PATCH 2/4] fix rename text not acting as vanilla --- .../cuanvil/dependency/util/PlatformUtil.kt | 37 ++++++++++--------- .../alexcrea/cuanvil/anvil/AnvilMergeLogic.kt | 11 +++++- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/util/PlatformUtil.kt b/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/util/PlatformUtil.kt index 3f709c7f..ec34ad84 100644 --- a/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/util/PlatformUtil.kt +++ b/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/util/PlatformUtil.kt @@ -37,7 +37,7 @@ object PlatformUtil { // Lore fun ItemMeta.componentLore(): MutableList { val lore: List? - if(isPaper){ + if (isPaper) { lore = this.lore() } else { val legacyLores = this.lore ?: return ArrayList() @@ -52,13 +52,15 @@ object PlatformUtil { } fun ItemMeta.setComponentLore(lore: List) { - if(isPaper){ + if (isPaper) { this.lore(lore) } else { val legacyLore = ArrayList(lore.size) for (component in lore) { - legacyLore.add(if(component == null) null - else legacy_mm.serialize(component)) + legacyLore.add( + if (component == null) null + else legacy_mm.serialize(component) + ) } this.lore = legacyLore @@ -69,32 +71,31 @@ object PlatformUtil { private val useCustomName = hasMethod(ItemStack::class.java, "customName") fun ItemMeta.componentDisplayName(): Component? { - if(useCustomName){ - if(!this.hasCustomName()) return null + if (useCustomName) { + if (!this.hasCustomName()) return null return this.customName() - }else if(isPaper){ - if(!this.hasDisplayName()) return null - return this.displayName() - } else { - if(!this.hasDisplayName()) return null + } + if (!this.hasDisplayName()) return null - val legacy = this.displayName - return legacy_mm.deserialize(legacy) + return if (isPaper) { + this.displayName() + } else { + legacy_mm.deserialize(this.displayName) } } - fun ItemMeta.setComponentDisplayName(component: Component?) { - if(useCustomName){ + fun ItemMeta.setComponentDisplayName(component: Component?, fallback: String? = null) { + if (useCustomName) { this.customName(component) - }else if(isPaper){ + } else if (isPaper) { this.displayName(component) } else { - if(component == null){ + if (component == null) { this.setDisplayName(null) return } - val legacy = legacy_mm.serialize(component) + val legacy = fallback ?: legacy_mm.serialize(component) this.setDisplayName(legacy) } } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt index fd7055ed..f398fd97 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt @@ -6,6 +6,7 @@ import io.delilaheve.util.EnchantmentUtil.combineWith import io.delilaheve.util.ItemUtil.isEnchantedBook import io.delilaheve.util.ItemUtil.repairFrom import io.delilaheve.util.ItemUtil.unitRepair +import net.kyori.adventure.text.Component import org.bukkit.ChatColor import org.bukkit.Material import org.bukkit.entity.HumanEntity @@ -17,6 +18,7 @@ import org.bukkit.inventory.meta.ItemMeta import org.bukkit.persistence.PersistentDataType import xyz.alexcrea.cuanvil.api.EnchantmentApi import xyz.alexcrea.cuanvil.dependency.DependencyManager +import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.setComponentDisplayName import xyz.alexcrea.cuanvil.dialog.AnvilRenameDialog import xyz.alexcrea.cuanvil.enchant.CAEnchantment import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe @@ -139,11 +141,12 @@ object AnvilMergeLogic { private fun handleRename(resultItem: ItemStack, inventory: AnvilInventory, player: HumanEntity): Int { // Can be null var renameText = ChatColor.stripColor(inventory.renameText) + var component: Component? = null var sumCost = 0 var useColor = false if (ConfigOptions.renameColorPossible && renameText != null) { - val component = AnvilColorUtil.handleColor( + component = AnvilColorUtil.handleColor( renameText, AnvilColorUtil.renamePermission(player) ) @@ -170,7 +173,11 @@ object AnvilMergeLogic { renameText == CasedStringUtil.snakeToUpperSpacedCase(resultItem.type.name.lowercase()) ) ) { - it.setDisplayName(renameText) + if (component == null) + component = if (renameText == null || renameText.isEmpty()) null + else Component.text(renameText) + it.setComponentDisplayName(component, renameText) + processDialogPCD(it, player) resultItem.itemMeta = it From 8830b4c4ed539e0ffe834954650ee1e152da047f Mon Sep 17 00:00:00 2001 From: alexcrea Date: Thu, 16 Jul 2026 18:50:51 +0200 Subject: [PATCH 3/4] remove use of customname as not used under 1.21.4 --- .../alexcrea/cuanvil/dependency/util/PlatformUtil.kt | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/util/PlatformUtil.kt b/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/util/PlatformUtil.kt index ec34ad84..aaa218fa 100644 --- a/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/util/PlatformUtil.kt +++ b/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/util/PlatformUtil.kt @@ -67,14 +67,7 @@ object PlatformUtil { } } - // Display name - private val useCustomName = hasMethod(ItemStack::class.java, "customName") - fun ItemMeta.componentDisplayName(): Component? { - if (useCustomName) { - if (!this.hasCustomName()) return null - return this.customName() - } if (!this.hasDisplayName()) return null return if (isPaper) { @@ -85,9 +78,7 @@ object PlatformUtil { } fun ItemMeta.setComponentDisplayName(component: Component?, fallback: String? = null) { - if (useCustomName) { - this.customName(component) - } else if (isPaper) { + if (isPaper) { this.displayName(component) } else { if (component == null) { From 9fc02034567931a279a6f863d81c9381a216929a Mon Sep 17 00:00:00 2001 From: alexcrea Date: Thu, 16 Jul 2026 19:09:16 +0200 Subject: [PATCH 4/4] check isAir instead of null --- src/main/kotlin/io/delilaheve/util/ItemUtil.kt | 4 ++-- .../xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt | 5 +++-- src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt | 1 - 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/io/delilaheve/util/ItemUtil.kt b/src/main/kotlin/io/delilaheve/util/ItemUtil.kt index 5bac8f0e..dba79b28 100644 --- a/src/main/kotlin/io/delilaheve/util/ItemUtil.kt +++ b/src/main/kotlin/io/delilaheve/util/ItemUtil.kt @@ -75,6 +75,6 @@ object ItemUtil { * The two items should either be the same type, or, the [other] is a book */ fun ItemStack.canMergeWith( - other: ItemStack? - ) = (other != null) && (customType == other.customType || (other.isEnchantedBook())) + other: ItemStack + ) = customType == other.customType || (other.isEnchantedBook()) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt index dd35ed69..7ab1037f 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt @@ -31,6 +31,7 @@ import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_INPUT_ import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_INPUT_RIGHT import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT import xyz.alexcrea.cuanvil.util.CustomRecipeUtil +import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir import xyz.alexcrea.cuanvil.util.MiniMessageUtil import xyz.alexcrea.cuanvil.util.anvil.AnvilLoreEditUtil import xyz.alexcrea.cuanvil.util.anvil.AnvilXpUtil @@ -92,7 +93,7 @@ class AnvilResultListener : Listener { } // Rename - if (rightItem == null) { + if (rightItem.isAir) { val result = AnvilMergeLogic.doRenaming(view, inventory, player, leftItem) if (result.isEmpty()) return @@ -106,7 +107,7 @@ class AnvilResultListener : Listener { } // Merge - val canMerge = leftItem.canMergeWith(rightItem) + val canMerge = leftItem.canMergeWith(rightItem!!) if (canMerge) { val result = AnvilMergeLogic.doMerge(view, inventory, player, leftItem, rightItem) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt index dc1e25a9..af5020c7 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt @@ -1,6 +1,5 @@ package xyz.alexcrea.cuanvil.util -import org.bukkit.Bukkit import org.bukkit.Material import org.bukkit.NamespacedKey import org.bukkit.inventory.ItemStack