mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 08:25:56 +02:00
fix rename text not acting as vanilla
This commit is contained in:
parent
deaf428fcb
commit
7082da7beb
2 changed files with 28 additions and 20 deletions
|
|
@ -57,8 +57,10 @@ object PlatformUtil {
|
||||||
} else {
|
} else {
|
||||||
val legacyLore = ArrayList<String?>(lore.size)
|
val legacyLore = ArrayList<String?>(lore.size)
|
||||||
for (component in lore) {
|
for (component in lore) {
|
||||||
legacyLore.add(if(component == null) null
|
legacyLore.add(
|
||||||
else legacy_mm.serialize(component))
|
if (component == null) null
|
||||||
|
else legacy_mm.serialize(component)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lore = legacyLore
|
this.lore = legacyLore
|
||||||
|
|
@ -72,18 +74,17 @@ object PlatformUtil {
|
||||||
if (useCustomName) {
|
if (useCustomName) {
|
||||||
if (!this.hasCustomName()) return null
|
if (!this.hasCustomName()) return null
|
||||||
return this.customName()
|
return this.customName()
|
||||||
}else if(isPaper){
|
}
|
||||||
if (!this.hasDisplayName()) return null
|
if (!this.hasDisplayName()) return null
|
||||||
return this.displayName()
|
|
||||||
|
return if (isPaper) {
|
||||||
|
this.displayName()
|
||||||
} else {
|
} else {
|
||||||
if(!this.hasDisplayName()) return null
|
legacy_mm.deserialize(this.displayName)
|
||||||
|
|
||||||
val legacy = this.displayName
|
|
||||||
return legacy_mm.deserialize(legacy)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ItemMeta.setComponentDisplayName(component: Component?) {
|
fun ItemMeta.setComponentDisplayName(component: Component?, fallback: String? = null) {
|
||||||
if (useCustomName) {
|
if (useCustomName) {
|
||||||
this.customName(component)
|
this.customName(component)
|
||||||
} else if (isPaper) {
|
} else if (isPaper) {
|
||||||
|
|
@ -94,7 +95,7 @@ object PlatformUtil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val legacy = legacy_mm.serialize(component)
|
val legacy = fallback ?: legacy_mm.serialize(component)
|
||||||
this.setDisplayName(legacy)
|
this.setDisplayName(legacy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import io.delilaheve.util.EnchantmentUtil.combineWith
|
||||||
import io.delilaheve.util.ItemUtil.isEnchantedBook
|
import io.delilaheve.util.ItemUtil.isEnchantedBook
|
||||||
import io.delilaheve.util.ItemUtil.repairFrom
|
import io.delilaheve.util.ItemUtil.repairFrom
|
||||||
import io.delilaheve.util.ItemUtil.unitRepair
|
import io.delilaheve.util.ItemUtil.unitRepair
|
||||||
|
import net.kyori.adventure.text.Component
|
||||||
import org.bukkit.ChatColor
|
import org.bukkit.ChatColor
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.entity.HumanEntity
|
import org.bukkit.entity.HumanEntity
|
||||||
|
|
@ -16,6 +17,7 @@ import org.bukkit.inventory.view.AnvilView
|
||||||
import org.bukkit.persistence.PersistentDataType
|
import org.bukkit.persistence.PersistentDataType
|
||||||
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
||||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||||
|
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.setComponentDisplayName
|
||||||
import xyz.alexcrea.cuanvil.dialog.AnvilRenameDialog
|
import xyz.alexcrea.cuanvil.dialog.AnvilRenameDialog
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||||
import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe
|
import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe
|
||||||
|
|
@ -138,11 +140,12 @@ object AnvilMergeLogic {
|
||||||
private fun handleRename(resultItem: ItemStack, view: AnvilView, player: HumanEntity): Int {
|
private fun handleRename(resultItem: ItemStack, view: AnvilView, player: HumanEntity): Int {
|
||||||
// Can be null
|
// Can be null
|
||||||
var renameText = ChatColor.stripColor(view.renameText)
|
var renameText = ChatColor.stripColor(view.renameText)
|
||||||
|
var component: Component? = null
|
||||||
|
|
||||||
var sumCost = 0
|
var sumCost = 0
|
||||||
var useColor = false
|
var useColor = false
|
||||||
if (ConfigOptions.renameColorPossible && renameText != null) {
|
if (ConfigOptions.renameColorPossible && renameText != null) {
|
||||||
val component = AnvilColorUtil.handleColor(
|
component = AnvilColorUtil.handleColor(
|
||||||
renameText,
|
renameText,
|
||||||
AnvilColorUtil.renamePermission(player)
|
AnvilColorUtil.renamePermission(player)
|
||||||
)
|
)
|
||||||
|
|
@ -169,7 +172,11 @@ object AnvilMergeLogic {
|
||||||
renameText == CasedStringUtil.snakeToUpperSpacedCase(resultItem.type.name.lowercase())
|
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)
|
processDialogPCD(it, player)
|
||||||
resultItem.itemMeta = it
|
resultItem.itemMeta = it
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue