Make sure rename work when null

This commit is contained in:
alexcrea 2025-01-24 12:13:44 +01:00
parent 5f557e3d49
commit 1db6385082
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F

View file

@ -116,15 +116,12 @@ class PrepareAnvilListener : Listener {
} }
private fun handleRename(resultItem: ItemStack, inventory: AnvilInventory, player: HumanEntity): Int { private fun handleRename(resultItem: ItemStack, inventory: AnvilInventory, player: HumanEntity): Int {
// Rename item and add renaming cost // Can be null
resultItem.itemMeta?.let {
val displayName = ChatColor.stripColor(it.displayName)
var inventoryName = ChatColor.stripColor(inventory.renameText) var inventoryName = ChatColor.stripColor(inventory.renameText)
var sumCost = 0 var sumCost = 0
var useColor = false var useColor = false
if(ConfigOptions.renameColorPossible){ if(ConfigOptions.renameColorPossible && inventoryName != null){
val resultString = StringBuilder(inventoryName) val resultString = StringBuilder(inventoryName)
useColor = AnvilColorUtil.handleRenamingColor(resultString, player) useColor = AnvilColorUtil.handleRenamingColor(resultString, player)
@ -136,6 +133,10 @@ class PrepareAnvilListener : Listener {
} }
} }
// Rename item and add renaming cost
resultItem.itemMeta?.let {
val displayName = ChatColor.stripColor(it.displayName)
if ((!useColor && (!displayName.contentEquals(inventoryName))) || (useColor && !(it.displayName).contentEquals(inventoryName))) { if ((!useColor && (!displayName.contentEquals(inventoryName))) || (useColor && !(it.displayName).contentEquals(inventoryName))) {
it.setDisplayName(inventoryName) it.setDisplayName(inventoryName)
resultItem.itemMeta = it resultItem.itemMeta = it