mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 16:35:57 +02:00
Compare commits
4 commits
37cd603575
...
9fc0203456
| Author | SHA1 | Date | |
|---|---|---|---|
| 9fc0203456 | |||
| 8830b4c4ed | |||
| 7b232528f1 | |||
| da10f0df5f |
6 changed files with 35 additions and 34 deletions
|
|
@ -57,36 +57,28 @@ 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display name
|
|
||||||
private val useCustomName = hasMethod(ItemStack::class.java, "customName")
|
|
||||||
|
|
||||||
fun ItemMeta.componentDisplayName(): Component? {
|
fun ItemMeta.componentDisplayName(): Component? {
|
||||||
if(useCustomName){
|
|
||||||
if(!this.hasCustomName()) return null
|
|
||||||
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 (isPaper) {
|
||||||
this.customName(component)
|
|
||||||
}else if(isPaper){
|
|
||||||
this.displayName(component)
|
this.displayName(component)
|
||||||
} else {
|
} else {
|
||||||
if (component == null) {
|
if (component == null) {
|
||||||
|
|
@ -94,7 +86,7 @@ object PlatformUtil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val legacy = legacy_mm.serialize(component)
|
val legacy = fallback ?: legacy_mm.serialize(component)
|
||||||
this.setDisplayName(legacy)
|
this.setDisplayName(legacy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
override fun onEnable() {
|
override fun onEnable() {
|
||||||
instance = this
|
instance = this
|
||||||
try {
|
try {
|
||||||
legacyCheck()
|
if(legacyCheck()) return
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.log(Level.SEVERE, "error trying to check for legacy system", e)
|
logger.log(Level.SEVERE, "error trying to check for legacy system", e)
|
||||||
MetricsUtil.trackError(e)
|
MetricsUtil.trackError(e)
|
||||||
|
|
@ -202,14 +202,15 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun legacyCheck() {
|
private fun legacyCheck(): Boolean {
|
||||||
val currentVersion = UpdateUtils.currentMinecraftVersion()
|
val currentVersion = UpdateUtils.currentMinecraftVersion()
|
||||||
if (currentVersion.greaterEqual(Version(1, 21, 0))
|
if (currentVersion.greaterEqual(Version(1, 21, 0))
|
||||||
&& !DependencyManager.inTesting) {
|
&& !DependencyManager.inTesting
|
||||||
|
&& !"true".equals(System.getenv("CUSTOM_ANVIL_BYPASS_LEGACY_CHECK"), true)) {
|
||||||
logger.warning("You are running a Minecraft version above or equal to 1.21.0")
|
logger.warning("You are running a Minecraft version above or equal to 1.21.0")
|
||||||
logger.warning("Please use CustomAnvil v2 instead if you wish to use the plugin with this version.")
|
logger.warning("Please use CustomAnvil v2 instead if you wish to use the plugin with this version.")
|
||||||
Bukkit.getPluginManager().disablePlugin(this)
|
Bukkit.getPluginManager().disablePlugin(this)
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
// Disable old plugin name if exist
|
// Disable old plugin name if exist
|
||||||
val potentialPlugin = Bukkit.getPluginManager().getPlugin("UnsafeEnchantsPlus")
|
val potentialPlugin = Bukkit.getPluginManager().getPlugin("UnsafeEnchantsPlus")
|
||||||
|
|
@ -242,6 +243,7 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
|
|
||||||
logger.warning("An update may be available: $latestVer")
|
logger.warning("An update may be available: $latestVer")
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun registerListeners() {
|
private fun registerListeners() {
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,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
|
||||||
) = (other != null) && (customType == other.customType || (other.isEnchantedBook()))
|
) = customType == other.customType || (other.isEnchantedBook())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -17,6 +18,7 @@ import org.bukkit.inventory.meta.ItemMeta
|
||||||
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
|
||||||
|
|
@ -139,11 +141,12 @@ object AnvilMergeLogic {
|
||||||
private fun handleRename(resultItem: ItemStack, inventory: AnvilInventory, player: HumanEntity): Int {
|
private fun handleRename(resultItem: ItemStack, inventory: AnvilInventory, player: HumanEntity): Int {
|
||||||
// Can be null
|
// Can be null
|
||||||
var renameText = ChatColor.stripColor(inventory.renameText)
|
var renameText = ChatColor.stripColor(inventory.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)
|
||||||
)
|
)
|
||||||
|
|
@ -170,7 +173,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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ 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
|
||||||
|
|
@ -92,7 +93,7 @@ class AnvilResultListener : Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rename
|
// Rename
|
||||||
if (rightItem == null) {
|
if (rightItem.isAir) {
|
||||||
val result = AnvilMergeLogic.doRenaming(view, inventory, player, leftItem)
|
val result = AnvilMergeLogic.doRenaming(view, inventory, player, leftItem)
|
||||||
if (result.isEmpty()) return
|
if (result.isEmpty()) return
|
||||||
|
|
||||||
|
|
@ -106,7 +107,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, inventory, player, leftItem, rightItem)
|
val result = AnvilMergeLogic.doMerge(view, inventory, player, leftItem, rightItem)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package xyz.alexcrea.cuanvil.util
|
package xyz.alexcrea.cuanvil.util
|
||||||
|
|
||||||
import org.bukkit.Bukkit
|
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.NamespacedKey
|
import org.bukkit.NamespacedKey
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue