diff --git a/build.gradle.kts b/build.gradle.kts index 64f17e1..3ff7fe6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ val githubActor = project.findProperty("gpr.user") as String? ?: System.getenv(" val githubToken = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") group = "me.tech" -version = "1.5.4" +version = "1.5.5" repositories { mavenCentral() diff --git a/src/main/kotlin/me/tech/mcchestui/GUI.kt b/src/main/kotlin/me/tech/mcchestui/GUI.kt index b15675d..4463b7a 100644 --- a/src/main/kotlin/me/tech/mcchestui/GUI.kt +++ b/src/main/kotlin/me/tech/mcchestui/GUI.kt @@ -116,6 +116,11 @@ class GUI( */ var onPickupItem: GUIItemPickupEvent? = null + /** + * Event called when a [ItemStack] is taken from a [PlayerInventory]. + */ + var onPlayerInventoryPickupItem: GUIItemPickupEvent? = null + /** * Event called when an item is dragged across a [GUI]. * Requires [allowItemPlacement] to be true to work. diff --git a/src/main/kotlin/me/tech/mcchestui/listeners/hotbar/GUIHotbarListener.kt b/src/main/kotlin/me/tech/mcchestui/listeners/hotbar/GUIHotbarListener.kt index 6c53c08..083e903 100644 --- a/src/main/kotlin/me/tech/mcchestui/listeners/hotbar/GUIHotbarListener.kt +++ b/src/main/kotlin/me/tech/mcchestui/listeners/hotbar/GUIHotbarListener.kt @@ -47,7 +47,7 @@ internal class GUIHotbarListener(gui: GUI) : GUIEventListener(gui) { currentItem } ?: return - if(itemStack.type == Material.AIR) { + if(itemStack.type.isEmpty) { return } @@ -92,7 +92,7 @@ internal class GUIHotbarListener(gui: GUI) : GUIEventListener(gui) { val itemStack = currentItem ?: return - if(itemStack.type == Material.AIR) { + if(itemStack.type.isEmpty) { return } diff --git a/src/main/kotlin/me/tech/mcchestui/listeners/item/GUIItemPickupListener.kt b/src/main/kotlin/me/tech/mcchestui/listeners/item/GUIItemPickupListener.kt index 63aac2a..895e434 100644 --- a/src/main/kotlin/me/tech/mcchestui/listeners/item/GUIItemPickupListener.kt +++ b/src/main/kotlin/me/tech/mcchestui/listeners/item/GUIItemPickupListener.kt @@ -21,6 +21,18 @@ internal class GUIItemPickupListener(gui: GUI): GUIEventListener(gui) { return } + if(clickedInventory == whoClicked.inventory) { + if(currentItem == null || currentItem?.type?.isEmpty == true) { + return + } + + gui.onPlayerInventoryPickupItem?.let { uiEvent -> + uiEvent(this, whoClicked as Player, currentItem, slot).let { outcome -> + isCancelled = outcome + } + } + } + // handle shift click if( action == InventoryAction.MOVE_TO_OTHER_INVENTORY @@ -53,7 +65,7 @@ internal class GUIItemPickupListener(gui: GUI): GUIEventListener(gui) { val itemStack = currentItem ?: return - if(itemStack.type == Material.AIR) { + if(itemStack.type.isEmpty) { return }