mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 16:35:57 +02:00
Compare commits
No commits in common. "f2f39dc326775e06ad458f41257b44acdbd690f4" and "deaf428fcbed0dd7eb60c78c19aaeea73de29e90" have entirely different histories.
f2f39dc326
...
deaf428fcb
4 changed files with 25 additions and 34 deletions
|
|
@ -57,10 +57,8 @@ 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(
|
legacyLore.add(if(component == null) null
|
||||||
if (component == null) null
|
else legacy_mm.serialize(component))
|
||||||
else legacy_mm.serialize(component)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lore = legacyLore
|
this.lore = legacyLore
|
||||||
|
|
@ -68,23 +66,24 @@ object PlatformUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display name
|
// Display name
|
||||||
private val useCustomName = hasMethod(ItemMeta::class.java, "customName")
|
private val useCustomName = hasMethod(ItemStack::class.java, "customName")
|
||||||
|
|
||||||
fun ItemMeta.componentDisplayName(): Component? {
|
fun ItemMeta.componentDisplayName(): Component? {
|
||||||
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
|
||||||
|
return this.displayName()
|
||||||
|
} else {
|
||||||
if(!this.hasDisplayName()) return null
|
if(!this.hasDisplayName()) return null
|
||||||
|
|
||||||
return if (isPaper) {
|
val legacy = this.displayName
|
||||||
this.displayName()
|
return legacy_mm.deserialize(legacy)
|
||||||
} else {
|
|
||||||
legacy_mm.deserialize(this.displayName)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ItemMeta.setComponentDisplayName(component: Component?, fallback: String? = null) {
|
fun ItemMeta.setComponentDisplayName(component: Component?) {
|
||||||
if(useCustomName){
|
if(useCustomName){
|
||||||
this.customName(component)
|
this.customName(component)
|
||||||
}else if(isPaper){
|
}else if(isPaper){
|
||||||
|
|
@ -95,7 +94,7 @@ object PlatformUtil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val legacy = fallback ?: legacy_mm.serialize(component)
|
val legacy = legacy_mm.serialize(component)
|
||||||
this.setDisplayName(legacy)
|
this.setDisplayName(legacy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,6 @@ object ItemUtil {
|
||||||
* The two items should either be the same type, or, the [other] is a book
|
* The two items should either be the same type, or, the [other] is a book
|
||||||
*/
|
*/
|
||||||
fun ItemStack.canMergeWith(
|
fun ItemStack.canMergeWith(
|
||||||
other: ItemStack
|
other: ItemStack?
|
||||||
) = customType == other.customType || (other.isEnchantedBook())
|
) = (other != null) && (customType == other.customType || (other.isEnchantedBook()))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ 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
|
||||||
|
|
@ -17,7 +16,6 @@ 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
|
||||||
|
|
@ -140,12 +138,11 @@ 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) {
|
||||||
component = AnvilColorUtil.handleColor(
|
val component = AnvilColorUtil.handleColor(
|
||||||
renameText,
|
renameText,
|
||||||
AnvilColorUtil.renamePermission(player)
|
AnvilColorUtil.renamePermission(player)
|
||||||
)
|
)
|
||||||
|
|
@ -172,11 +169,7 @@ object AnvilMergeLogic {
|
||||||
renameText == CasedStringUtil.snakeToUpperSpacedCase(resultItem.type.name.lowercase())
|
renameText == CasedStringUtil.snakeToUpperSpacedCase(resultItem.type.name.lowercase())
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
if (component == null)
|
it.setDisplayName(renameText)
|
||||||
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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_INPUT_
|
||||||
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_INPUT_RIGHT
|
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_INPUT_RIGHT
|
||||||
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT
|
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT
|
||||||
import xyz.alexcrea.cuanvil.util.CustomRecipeUtil
|
import xyz.alexcrea.cuanvil.util.CustomRecipeUtil
|
||||||
import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir
|
|
||||||
import xyz.alexcrea.cuanvil.util.MiniMessageUtil
|
import xyz.alexcrea.cuanvil.util.MiniMessageUtil
|
||||||
import xyz.alexcrea.cuanvil.util.anvil.AnvilLoreEditUtil
|
import xyz.alexcrea.cuanvil.util.anvil.AnvilLoreEditUtil
|
||||||
import xyz.alexcrea.cuanvil.util.anvil.AnvilXpUtil
|
import xyz.alexcrea.cuanvil.util.anvil.AnvilXpUtil
|
||||||
|
|
@ -93,7 +92,7 @@ class AnvilResultListener : Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rename
|
// Rename
|
||||||
if (rightItem.isAir) {
|
if (rightItem == null) {
|
||||||
val result = AnvilMergeLogic.doRenaming(view, player, leftItem)
|
val result = AnvilMergeLogic.doRenaming(view, player, leftItem)
|
||||||
if (result.isEmpty()) return
|
if (result.isEmpty()) return
|
||||||
|
|
||||||
|
|
@ -107,7 +106,7 @@ class AnvilResultListener : Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge
|
// Merge
|
||||||
val canMerge = leftItem.canMergeWith(rightItem!!)
|
val canMerge = leftItem.canMergeWith(rightItem)
|
||||||
if (canMerge) {
|
if (canMerge) {
|
||||||
val result = AnvilMergeLogic.doMerge(view, player, leftItem, rightItem)
|
val result = AnvilMergeLogic.doMerge(view, player, leftItem, rightItem)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue