Only trigger click on mouse click action - else cancel

This commit is contained in:
bluefireoly
2020-10-22 01:53:04 +02:00
parent bbc447ff5d
commit 661af86ead

View File

@@ -1,6 +1,7 @@
package net.axay.kspigot.inventory package net.axay.kspigot.inventory
import net.axay.kspigot.event.listen import net.axay.kspigot.event.listen
import org.bukkit.event.inventory.InventoryAction
import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.inventory.InventoryClickEvent
object InventoryGUIHolder : AutoCloseable { object InventoryGUIHolder : AutoCloseable {
@@ -28,11 +29,10 @@ object InventoryGUIHolder : AutoCloseable {
return@listen return@listen
} }
val invPage = inv.currentPageInt if (it.action.isGUIClick)
inv.currentPage.slots[it.slot]?.onClick(InventoryGUIClickEvent(it, inv)) ?: kotlin.run {
val slot = inv.data.pages[invPage]?.slots?.get(it.slot) it.isCancelled = true
if (slot != null) }
slot.onClick(InventoryGUIClickEvent(it, inv))
else else
it.isCancelled = true it.isCancelled = true
@@ -44,4 +44,7 @@ object InventoryGUIHolder : AutoCloseable {
registered.clear() registered.clear()
} }
} }
private val InventoryAction.isGUIClick
get() = this == InventoryAction.PICKUP_ALL || this == InventoryAction.PICKUP_HALF