mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 00:15:56 +02:00
add support for enchantedbook
This commit is contained in:
parent
16e4f0a923
commit
b9ff4bdc40
6 changed files with 50 additions and 8 deletions
|
|
@ -40,6 +40,8 @@ Custom Items support is considered unstable. If you find issue please report it
|
|||
- [Disenchantment](https://www.spigotmc.org/resources/disenchantment-1-21-1-1-20-6-new-book-splitting-mechanics.110741/) by H7KZ
|
||||
Partially use Custom Anvil maximum XP settings (>= 6.1.5)
|
||||
|
||||
- [EnchantedBook](https://modrinth.com/plugin/enchantedbook) by Minacle
|
||||
|
||||
- [HavenBags](https://www.spigotmc.org/resources/havenbags-shulker-like-player-bound-bags-1-17-1-21-4.110420/) by hyperdefined
|
||||
For bag upgrade and skin via anvil. (version >= 1.31.0)
|
||||
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ class DiagnosticExecutor: CASubCommand() {
|
|||
try {
|
||||
val fakeInv = Bukkit.createInventory(player, InventoryType.ANVIL)
|
||||
invView = player.openInventory(fakeInv)!!
|
||||
event = PrepareAnvilEvent(invView, result)
|
||||
event = DependencyManager.createFakeEvent(invView, result)
|
||||
} catch (e: Throwable) {
|
||||
// Help
|
||||
val menuTypeClazz = Class.forName("org.bukkit.inventory.MenuType")
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
|
|||
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.componentLore
|
||||
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT
|
||||
import xyz.alexcrea.cuanvil.util.MetricsUtil.trackError
|
||||
import java.lang.reflect.Constructor
|
||||
import java.util.logging.Level
|
||||
|
||||
object DependencyManager {
|
||||
|
|
@ -103,7 +104,7 @@ object DependencyManager {
|
|||
axPlayerWarpsCompatibility = AxPlayerWarpsDependency()
|
||||
}
|
||||
|
||||
if (pluginManager.isPluginEnabled("ItemsAdder")){
|
||||
if (pluginManager.isPluginEnabled("ItemsAdder")) {
|
||||
val dependency = ItemsAdderDependency(pluginManager.getPlugin("ItemsAdder")!!)
|
||||
itemsAdderCompatibility = dependency
|
||||
genericDependencies.add(dependency)
|
||||
|
|
@ -116,12 +117,16 @@ object DependencyManager {
|
|||
if (pluginManager.isPluginEnabled("ItemsAdder"))
|
||||
genericDependencies.add(GenericPluginDependency(pluginManager.getPlugin("ItemsAdder")!!))
|
||||
|
||||
if (pluginManager.isPluginEnabled("SuperEnchants")){
|
||||
if (pluginManager.isPluginEnabled("SuperEnchants")) {
|
||||
val compatibility = SuperEnchantDependency(pluginManager.getPlugin("SuperEnchants")!! as SuperEnchants)
|
||||
if(compatibility.registerEnchantments())
|
||||
if (compatibility.registerEnchantments())
|
||||
genericDependencies.add(compatibility)
|
||||
}
|
||||
|
||||
if (pluginManager.isPluginEnabled("EnchantedBook")) {
|
||||
genericDependencies.add(EnchantedBookDependency(pluginManager.getPlugin("EnchantedBook")!!))
|
||||
}
|
||||
|
||||
for (dependency in genericDependencies)
|
||||
dependency.redirectListeners()
|
||||
|
||||
|
|
@ -307,7 +312,7 @@ object DependencyManager {
|
|||
|
||||
private fun unsafeCloneItem(item: ItemStack): ItemStack {
|
||||
val cloned = itemsAdderCompatibility?.tryClone(item)
|
||||
if(cloned != null) return cloned
|
||||
if (cloned != null) return cloned
|
||||
|
||||
return item.clone()
|
||||
}
|
||||
|
|
@ -328,4 +333,12 @@ object DependencyManager {
|
|||
enchantmentSquaredCompatibility?.updateLore(item)
|
||||
}
|
||||
|
||||
|
||||
private val prepareAnvilConstructor =
|
||||
PrepareAnvilEvent::class.java.constructors.first() as Constructor<PrepareAnvilEvent>
|
||||
|
||||
fun createFakeEvent(view: InventoryView, result: ItemStack?): PrepareAnvilEvent {
|
||||
return prepareAnvilConstructor.newInstance(view, result)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.plugins
|
||||
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.plugin.Plugin
|
||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_INPUT_LEFT
|
||||
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT
|
||||
|
||||
class EnchantedBookDependency(plugin: Plugin) : GenericPluginDependency(plugin) {
|
||||
|
||||
override fun testAnvilResult(event: InventoryClickEvent): Boolean {
|
||||
val view = event.view
|
||||
|
||||
val current = view.getItem(ANVIL_OUTPUT_SLOT)
|
||||
view.setItem(ANVIL_OUTPUT_SLOT, null)
|
||||
val fakeEvent = DependencyManager.createFakeEvent(event.view, null)
|
||||
|
||||
if (testPrepareAnvil(fakeEvent)) {
|
||||
event.isCancelled = false
|
||||
return true
|
||||
}
|
||||
|
||||
view.setItem(ANVIL_INPUT_LEFT, current)
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ import org.bukkit.inventory.ItemStack
|
|||
import org.bukkit.plugin.RegisteredListener
|
||||
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
||||
import xyz.alexcrea.cuanvil.api.event.listener.CATreatAnvilResult2Event
|
||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEPreV5Enchantment
|
||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEV5Enchantment
|
||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEV5_4Enchantment
|
||||
|
|
@ -118,8 +119,6 @@ class ExcellentEnchantsDependency {
|
|||
private lateinit var handleRechargeMethod: Method
|
||||
private lateinit var handleCombineMethod: Method
|
||||
|
||||
private val prepareAnvilConstructor = PrepareAnvilEvent::class.java.constructors.first() as Constructor<PrepareAnvilEvent>
|
||||
|
||||
fun redirectListeners() {
|
||||
val toUnregister = ArrayList<RegisteredListener>()
|
||||
// get required PrepareAnvilEvent listener
|
||||
|
|
@ -226,7 +225,7 @@ class ExcellentEnchantsDependency {
|
|||
|
||||
val first: ItemStack = treatInput(event.leftItem)
|
||||
val second: ItemStack = treatInput(event.rightItem)
|
||||
val fakeEvent = prepareAnvilConstructor.newInstance(event.view, result)
|
||||
val fakeEvent = DependencyManager.createFakeEvent(event.view, result)
|
||||
|
||||
handleCombineMethod.invoke(this.usedAnvilListener, fakeEvent, first, second, result)
|
||||
|
||||
|
|
|
|||
|
|
@ -84,3 +84,4 @@ softdepend:
|
|||
- ExcellentEnchants
|
||||
- HavenBags
|
||||
- SuperEnchants
|
||||
- EnchantedBook
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue