11package trplugins.menu.module.internal.listener
22
3+ import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory
34import org.bukkit.event.player.PlayerInteractEvent
45import org.bukkit.inventory.EquipmentSlot
56import org.bukkit.inventory.Inventory
67import taboolib.common.platform.event.EventPriority
78import taboolib.common.platform.event.SubscribeEvent
89import taboolib.common5.Baffle
9- import taboolib.module.nms.MinecraftVersion
10+ import taboolib.module.nms.MinecraftVersion.versionId
11+ import taboolib.module.nms.nmsProxy
12+ import taboolib.module.nms.obcClass
1013import trplugins.menu.TrMenu
1114import trplugins.menu.api.event.MenuOpenEvent
1215import trplugins.menu.module.display.Menu
@@ -28,11 +31,15 @@ object ListenerItemInteract {
2831 fun onInteract (e : PlayerInteractEvent ) {
2932 ListenerItemInteract ::interactCooldown.get()
3033
31- if (MinecraftVersion .majorLegacy >= 10900 && e.hand == EquipmentSlot .OFF_HAND ) return
34+ if (versionId >= 10900 && e.hand == EquipmentSlot .OFF_HAND ) return
3235 val player = e.player
3336 val item = e.item ? : return
3437 val session = MenuSession .getSession(player)
3538
39+ if (! InventoryNMS .instance.checkInventory(player.openInventory.topInventory)
40+ || ! InventoryNMS .instance.checkInventory(player.inventory)
41+ ) return
42+
3643 if (player.openInventory.topInventory.holder != (player.inventory as Inventory ).holder || session.menu != null ) return
3744 if (interactCooldown.value.hasNext(player.name)) {
3845 val menu = Menu .menus.find { it -> it.settings.boundItems.any { it.itemMatches(item, true ) } }
@@ -43,4 +50,23 @@ object ListenerItemInteract {
4350 }
4451 }
4552
53+ class InventoryNMSImpl : InventoryNMS () {
54+
55+ private val `clazz$CraftInventoryCustom $MinecraftInventory ` =
56+ obcClass(" org.bukkit.craftbukkit.inventory.CraftInventoryCustom\$ MinecraftInventory" )
57+
58+ override fun checkInventory (inventory : Inventory ): Boolean {
59+ return `clazz$CraftInventoryCustom $MinecraftInventory `.isInstance((inventory as CraftInventory ).inventory)
60+ }
61+
62+ }
63+
64+ abstract class InventoryNMS {
65+ abstract fun checkInventory (inventory : Inventory ): Boolean
66+
67+ companion object {
68+ val instance by lazy { nmsProxy<InventoryNMS >() }
69+ }
70+ }
71+
4672}
0 commit comments