mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
made lore edit compatible with enchantment squared
This commit is contained in:
parent
f8555175c1
commit
fd7e7684d9
3 changed files with 48 additions and 9 deletions
|
|
@ -105,8 +105,12 @@ object DependencyManager {
|
|||
fun tryEventPreAnvilBypass(event: PrepareAnvilEvent, player: HumanEntity): Boolean {
|
||||
try {
|
||||
return unsafeTryEventPreAnvilBypass(event, player)
|
||||
} catch (e: Exception){
|
||||
CustomAnvil.instance.logger.log(Level.SEVERE, "Error while trying to handle custom anvil supported plugin: ", e)
|
||||
} catch (e: Exception) {
|
||||
CustomAnvil.instance.logger.log(
|
||||
Level.SEVERE,
|
||||
"Error while trying to handle custom anvil supported plugin: ",
|
||||
e
|
||||
)
|
||||
|
||||
// Just in case to avoid illegal items
|
||||
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
|
||||
|
|
@ -141,8 +145,12 @@ object DependencyManager {
|
|||
try {
|
||||
unsafeTryTreatAnvilResult(event, result)
|
||||
return false
|
||||
} catch (e: Exception){
|
||||
CustomAnvil.instance.logger.log(Level.SEVERE, "Error while trying to handle custom anvil supported plugin: ", e)
|
||||
} catch (e: Exception) {
|
||||
CustomAnvil.instance.logger.log(
|
||||
Level.SEVERE,
|
||||
"Error while trying to handle custom anvil supported plugin: ",
|
||||
e
|
||||
)
|
||||
|
||||
// Just in case to avoid illegal items
|
||||
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
|
||||
|
|
@ -161,8 +169,12 @@ object DependencyManager {
|
|||
fun tryClickAnvilResultBypass(event: InventoryClickEvent, inventory: AnvilInventory): Boolean {
|
||||
try {
|
||||
return unsafeTryClickAnvilResultBypass(event, inventory)
|
||||
} catch (e: Exception){
|
||||
CustomAnvil.instance.logger.log(Level.SEVERE, "Error while trying to handle custom anvil supported plugin: ", e)
|
||||
} catch (e: Exception) {
|
||||
CustomAnvil.instance.logger.log(
|
||||
Level.SEVERE,
|
||||
"Error while trying to handle custom anvil supported plugin: ",
|
||||
e
|
||||
)
|
||||
|
||||
// Just in case to avoid illegal items
|
||||
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
|
||||
|
|
@ -191,6 +203,21 @@ object DependencyManager {
|
|||
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 {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package xyz.alexcrea.cuanvil.util
|
||||
|
||||
import com.willfp.eco.util.toNiceString
|
||||
import org.bukkit.entity.HumanEntity
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.BookMeta
|
||||
import org.bukkit.permissions.Permissible
|
||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||
import xyz.alexcrea.cuanvil.util.config.LoreEditConfigUtil
|
||||
import xyz.alexcrea.cuanvil.util.config.LoreEditType
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
|
@ -60,13 +62,14 @@ object AnvilLoreEditUtil {
|
|||
// remove lore
|
||||
val result = first.clone()
|
||||
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)
|
||||
|
||||
leftMeta.lore = null
|
||||
result.itemMeta = leftMeta
|
||||
|
||||
DependencyManager.updateLore(result)
|
||||
if (result == first) return null
|
||||
|
||||
// Handle xp
|
||||
|
|
@ -182,7 +185,7 @@ object AnvilLoreEditUtil {
|
|||
val meta = result.itemMeta!!
|
||||
|
||||
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)
|
||||
else lore.removeAt(0)
|
||||
|
|
@ -195,6 +198,7 @@ object AnvilLoreEditUtil {
|
|||
tempList.add(line)
|
||||
val uncolorCost = uncolorLines(player, tempList, LoreEditType.REMOVE_PAPER)
|
||||
|
||||
DependencyManager.updateLore(result)
|
||||
if (result == first) return null
|
||||
|
||||
// Handle other xp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue