From 1db6385082aa1500f3f6afa4492b4c087cc2ff2e Mon Sep 17 00:00:00 2001 From: alexcrea <42614139+alexcrea@users.noreply.github.com> Date: Fri, 24 Jan 2025 12:13:44 +0100 Subject: [PATCH] Make sure rename work when null --- .../cuanvil/listener/PrepareAnvilListener.kt | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt index 68370d4..87afba6 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt @@ -116,26 +116,27 @@ class PrepareAnvilListener : Listener { } private fun handleRename(resultItem: ItemStack, inventory: AnvilInventory, player: HumanEntity): Int { + // Can be null + var inventoryName = ChatColor.stripColor(inventory.renameText) + + var sumCost = 0 + var useColor = false + if(ConfigOptions.renameColorPossible && inventoryName != null){ + val resultString = StringBuilder(inventoryName) + + useColor = AnvilColorUtil.handleRenamingColor(resultString, player) + + if(useColor) { + inventoryName = resultString.toString() + + sumCost+= ConfigOptions.useOfColorCost + } + } + // Rename item and add renaming cost resultItem.itemMeta?.let { + val displayName = ChatColor.stripColor(it.displayName) - var inventoryName = ChatColor.stripColor(inventory.renameText) - - var sumCost = 0 - - var useColor = false - if(ConfigOptions.renameColorPossible){ - val resultString = StringBuilder(inventoryName) - - useColor = AnvilColorUtil.handleRenamingColor(resultString, player) - - if(useColor) { - inventoryName = resultString.toString() - - sumCost+= ConfigOptions.useOfColorCost - } - } - if ((!useColor && (!displayName.contentEquals(inventoryName))) || (useColor && !(it.displayName).contentEquals(inventoryName))) { it.setDisplayName(inventoryName) resultItem.itemMeta = it