mirror of
https://github.com/Auxilor/Reforges.git
synced 2025-12-28 11:29:20 +00:00
Fixed reforge name duplication
This commit is contained in:
@@ -13,17 +13,26 @@ import com.willfp.reforges.reforges.util.ReforgeUtils
|
||||
import net.kyori.adventure.text.Component
|
||||
import net.kyori.adventure.text.TextReplacementConfig
|
||||
import net.kyori.adventure.text.format.TextDecoration
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.SkullMeta
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
class ReforgesDisplay(private val plugin: ReforgesPlugin) : DisplayModule(plugin, DisplayPriority.HIGHEST) {
|
||||
/**
|
||||
* Deprecated
|
||||
*/
|
||||
@Deprecated("Use PDC components!")
|
||||
private val replacement = TextReplacementConfig.builder()
|
||||
.match("§w(.+)§w")
|
||||
.replacement("")
|
||||
.build()
|
||||
|
||||
private val originalComponentKey = plugin.namespacedKeyFactory.create("real_name")
|
||||
private val serializer = GsonComponentSerializer.gson()
|
||||
|
||||
override fun display(
|
||||
itemStack: ItemStack,
|
||||
vararg args: Any
|
||||
@@ -76,12 +85,13 @@ class ReforgesDisplay(private val plugin: ReforgesPlugin) : DisplayModule(plugin
|
||||
lore.addAll(addLore)
|
||||
}
|
||||
if (plugin.configYml.getBool("reforge.display-in-name") && Prerequisite.HAS_PAPER.isMet) {
|
||||
val displayName =
|
||||
(if (meta.hasDisplayName()) meta.displayName()!! else Component.translatable(itemStack))
|
||||
.replaceText(
|
||||
replacement
|
||||
)
|
||||
val newName = StringUtils.toComponent("§w${reforge.name} §w")
|
||||
val displayName = (meta.displayName() ?: Component.translatable(itemStack)).replaceText(replacement)
|
||||
meta.persistentDataContainer.set(
|
||||
originalComponentKey,
|
||||
PersistentDataType.STRING,
|
||||
serializer.serialize(displayName)
|
||||
)
|
||||
val newName = StringUtils.toComponent("${reforge.name} ")
|
||||
.decoration(TextDecoration.ITALIC, false).append(displayName)
|
||||
meta.displayName(newName)
|
||||
}
|
||||
@@ -96,12 +106,10 @@ class ReforgesDisplay(private val plugin: ReforgesPlugin) : DisplayModule(plugin
|
||||
val meta = itemStack.itemMeta ?: return
|
||||
|
||||
if (plugin.configYml.getBool("reforge.display-in-name") && Prerequisite.HAS_PAPER.isMet) {
|
||||
val displayName = meta.displayName() ?: return
|
||||
meta.displayName(
|
||||
displayName.replaceText(
|
||||
replacement
|
||||
)
|
||||
)
|
||||
val originalName =
|
||||
meta.persistentDataContainer.get(originalComponentKey, PersistentDataType.STRING) ?: return
|
||||
meta.persistentDataContainer.remove(originalComponentKey)
|
||||
meta.displayName(serializer.deserialize(originalName).replaceText(replacement))
|
||||
}
|
||||
|
||||
itemStack.itemMeta = meta
|
||||
|
||||
Reference in New Issue
Block a user