fix rename text not acting as vanilla

This commit is contained in:
alexcrea 2026-07-16 18:44:23 +02:00
parent deaf428fcb
commit 7082da7beb
Signed by: alexcrea
GPG key ID: E59DF23EE2A2266C
2 changed files with 28 additions and 20 deletions

View file

@ -37,7 +37,7 @@ object PlatformUtil {
// Lore
fun ItemMeta.componentLore(): MutableList<Component> {
val lore: List<Component>?
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<Component?>) {
if(isPaper){
if (isPaper) {
this.lore(lore)
} else {
val legacyLore = ArrayList<String?>(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()
}
if (!this.hasDisplayName()) return null
return if (isPaper) {
this.displayName()
} else {
if(!this.hasDisplayName()) return null
val legacy = this.displayName
return legacy_mm.deserialize(legacy)
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)
}
}

View file

@ -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
@ -16,6 +17,7 @@ import org.bukkit.inventory.view.AnvilView
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
@ -138,11 +140,12 @@ object AnvilMergeLogic {
private fun handleRename(resultItem: ItemStack, view: AnvilView, player: HumanEntity): Int {
// Can be null
var renameText = ChatColor.stripColor(view.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)
)
@ -169,7 +172,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