made lore edit compatible with enchantment squared

This commit is contained in:
alexcrea 2025-03-21 17:04:50 +01:00
parent f8555175c1
commit fd7e7684d9
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
3 changed files with 48 additions and 9 deletions

View file

@ -105,8 +105,12 @@ object DependencyManager {
fun tryEventPreAnvilBypass(event: PrepareAnvilEvent, player: HumanEntity): Boolean { fun tryEventPreAnvilBypass(event: PrepareAnvilEvent, player: HumanEntity): Boolean {
try { try {
return unsafeTryEventPreAnvilBypass(event, player) return unsafeTryEventPreAnvilBypass(event, player)
} catch (e: Exception){ } catch (e: Exception) {
CustomAnvil.instance.logger.log(Level.SEVERE, "Error while trying to handle custom anvil supported plugin: ", e) CustomAnvil.instance.logger.log(
Level.SEVERE,
"Error while trying to handle custom anvil supported plugin: ",
e
)
// Just in case to avoid illegal items // Just in case to avoid illegal items
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null) event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
@ -141,8 +145,12 @@ object DependencyManager {
try { try {
unsafeTryTreatAnvilResult(event, result) unsafeTryTreatAnvilResult(event, result)
return false return false
} catch (e: Exception){ } catch (e: Exception) {
CustomAnvil.instance.logger.log(Level.SEVERE, "Error while trying to handle custom anvil supported plugin: ", e) CustomAnvil.instance.logger.log(
Level.SEVERE,
"Error while trying to handle custom anvil supported plugin: ",
e
)
// Just in case to avoid illegal items // Just in case to avoid illegal items
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null) event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
@ -161,8 +169,12 @@ object DependencyManager {
fun tryClickAnvilResultBypass(event: InventoryClickEvent, inventory: AnvilInventory): Boolean { fun tryClickAnvilResultBypass(event: InventoryClickEvent, inventory: AnvilInventory): Boolean {
try { try {
return unsafeTryClickAnvilResultBypass(event, inventory) return unsafeTryClickAnvilResultBypass(event, inventory)
} catch (e: Exception){ } catch (e: Exception) {
CustomAnvil.instance.logger.log(Level.SEVERE, "Error while trying to handle custom anvil supported plugin: ", e) CustomAnvil.instance.logger.log(
Level.SEVERE,
"Error while trying to handle custom anvil supported plugin: ",
e
)
// Just in case to avoid illegal items // Just in case to avoid illegal items
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null) event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
@ -191,6 +203,21 @@ object DependencyManager {
return bypass return bypass
} }
fun stripLore(item: ItemStack): ArrayList<String> {
val lore = ArrayList<String>()
val dummy = item.clone()
enchantmentSquaredCompatibility?.stripLore(dummy)
val itemLore = item.itemMeta!!.lore
if (itemLore != null) lore.addAll(itemLore)
return lore
}
fun updateLore(item: ItemStack) {
enchantmentSquaredCompatibility?.updateLore(item)
}
private fun testIsFolia(): Boolean { private fun testIsFolia(): Boolean {
try { try {

View file

@ -203,4 +203,12 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
} }
} }
fun stripLore(item: ItemStack) {
CustomEnchantManager.getInstance().removeAllEnchants(item)
}
fun updateLore(item: ItemStack) {
CustomEnchantManager.getInstance().updateLore(item)
}
} }

View file

@ -1,9 +1,11 @@
package xyz.alexcrea.cuanvil.util package xyz.alexcrea.cuanvil.util
import com.willfp.eco.util.toNiceString
import org.bukkit.entity.HumanEntity import org.bukkit.entity.HumanEntity
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.BookMeta import org.bukkit.inventory.meta.BookMeta
import org.bukkit.permissions.Permissible import org.bukkit.permissions.Permissible
import xyz.alexcrea.cuanvil.dependency.DependencyManager
import xyz.alexcrea.cuanvil.util.config.LoreEditConfigUtil import xyz.alexcrea.cuanvil.util.config.LoreEditConfigUtil
import xyz.alexcrea.cuanvil.util.config.LoreEditType import xyz.alexcrea.cuanvil.util.config.LoreEditType
import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicInteger
@ -60,13 +62,14 @@ object AnvilLoreEditUtil {
// remove lore // remove lore
val result = first.clone() val result = first.clone()
val leftMeta = result.itemMeta ?: return null val leftMeta = result.itemMeta ?: return null
val currentLore = ArrayList<String>(leftMeta.lore ?: return null) val currentLore: ArrayList<String> = DependencyManager.stripLore(result)
val uncolorCost = uncolorLines(player, currentLore, LoreEditType.REMOVE_BOOK) val uncolorCost = uncolorLines(player, currentLore, LoreEditType.REMOVE_BOOK)
leftMeta.lore = null leftMeta.lore = null
result.itemMeta = leftMeta result.itemMeta = leftMeta
DependencyManager.updateLore(result)
if (result == first) return null if (result == first) return null
// Handle xp // Handle xp
@ -182,7 +185,7 @@ object AnvilLoreEditUtil {
val meta = result.itemMeta!! val meta = result.itemMeta!!
val removeEnd = LoreEditConfigUtil.paperLoreOrderIsEnd val removeEnd = LoreEditConfigUtil.paperLoreOrderIsEnd
val lore: ArrayList<String> = ArrayList(meta.lore!!) val lore: ArrayList<String> = DependencyManager.stripLore(result)
val line = if (removeEnd) lore.removeAt(lore.size - 1) val line = if (removeEnd) lore.removeAt(lore.size - 1)
else lore.removeAt(0) else lore.removeAt(0)
@ -195,6 +198,7 @@ object AnvilLoreEditUtil {
tempList.add(line) tempList.add(line)
val uncolorCost = uncolorLines(player, tempList, LoreEditType.REMOVE_PAPER) val uncolorCost = uncolorLines(player, tempList, LoreEditType.REMOVE_PAPER)
DependencyManager.updateLore(result)
if (result == first) return null if (result == first) return null
// Handle other xp // Handle other xp