mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
fix fake prepare anvil on modern versions
This commit is contained in:
parent
49b0054eca
commit
2f9d25bfe9
2 changed files with 20 additions and 4 deletions
|
|
@ -0,0 +1,12 @@
|
||||||
|
package xyz.alexcrea.cuanvil.util
|
||||||
|
|
||||||
|
import org.bukkit.event.inventory.PrepareAnvilEvent
|
||||||
|
import org.bukkit.inventory.InventoryView
|
||||||
|
import org.bukkit.inventory.ItemStack
|
||||||
|
import org.bukkit.inventory.view.AnvilView
|
||||||
|
|
||||||
|
object ModernPrepareAnvilCreator {
|
||||||
|
fun createPrepareAnvil(view: InventoryView, item: ItemStack?): PrepareAnvilEvent {
|
||||||
|
return PrepareAnvilEvent(view as AnvilView, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,6 +13,7 @@ import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEPreV5Enchantment
|
||||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEV5Enchantment
|
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEV5Enchantment
|
||||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEV5_4Enchantment
|
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEV5_4Enchantment
|
||||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CALegacyEEEnchantment
|
import xyz.alexcrea.cuanvil.enchant.wrapped.CALegacyEEEnchantment
|
||||||
|
import xyz.alexcrea.cuanvil.util.ModernPrepareAnvilCreator
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
import su.nightexpress.excellentenchants.api.EnchantRegistry as V5EnchantRegistry
|
import su.nightexpress.excellentenchants.api.EnchantRegistry as V5EnchantRegistry
|
||||||
import su.nightexpress.excellentenchants.enchantment.impl.universal.CurseOfFragilityEnchant as LegacyCurseOfFragilityEnchant
|
import su.nightexpress.excellentenchants.enchantment.impl.universal.CurseOfFragilityEnchant as LegacyCurseOfFragilityEnchant
|
||||||
|
|
@ -219,13 +220,16 @@ class ExcellentEnchantsDependency {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun treatAnvilResult(event: CATreatAnvilResult2Event) {
|
fun treatAnvilResult(event: CATreatAnvilResult2Event) {
|
||||||
val result = event.result
|
val result = event.result ?: return
|
||||||
if (result == null) return
|
|
||||||
|
|
||||||
val first: ItemStack = treatInput(event.leftItem)
|
val first: ItemStack = treatInput(event.leftItem)
|
||||||
val second: ItemStack = treatInput(event.rightItem)
|
val second: ItemStack = treatInput(event.rightItem)
|
||||||
|
val fakeEvent: PrepareAnvilEvent = try {
|
||||||
val fakeEvent = PrepareAnvilEvent(event.view, result)
|
//TODO remove this on legacy removal
|
||||||
|
PrepareAnvilEvent(event.view, result)
|
||||||
|
} catch (_: NoSuchMethodError) {
|
||||||
|
ModernPrepareAnvilCreator.createPrepareAnvil(event.view, result)
|
||||||
|
}
|
||||||
handleCombineMethod.invoke(this.usedAnvilListener, fakeEvent, first, second, result)
|
handleCombineMethod.invoke(this.usedAnvilListener, fakeEvent, first, second, result)
|
||||||
|
|
||||||
event.result = fakeEvent.result
|
event.result = fakeEvent.result
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue