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,26 +116,27 @@ class PrepareAnvilListener : Listener {
} }
private fun handleRename(resultItem: ItemStack, inventory: AnvilInventory, player: HumanEntity): Int { 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 // Rename item and add renaming cost
resultItem.itemMeta?.let { resultItem.itemMeta?.let {
val displayName = ChatColor.stripColor(it.displayName) 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))) { if ((!useColor && (!displayName.contentEquals(inventoryName))) || (useColor && !(it.displayName).contentEquals(inventoryName))) {
it.setDisplayName(inventoryName) it.setDisplayName(inventoryName)
resultItem.itemMeta = it resultItem.itemMeta = it