From d664cc367ebb36c13b0edf363887301f3c48c646 Mon Sep 17 00:00:00 2001 From: Tech Date: Sun, 18 Aug 2024 13:33:32 -0400 Subject: [PATCH] feat: experimental shift clicking --- build.gradle.kts | 2 +- src/main/kotlin/me/tech/mcchestui/GUI.kt | 6 ++++++ .../listeners/item/GUIItemPlaceListener.kt | 21 +++++++++++-------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b23ce62..ffb860a 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.0" +version = "1.5.3" repositories { mavenCentral() diff --git a/src/main/kotlin/me/tech/mcchestui/GUI.kt b/src/main/kotlin/me/tech/mcchestui/GUI.kt index 7c496fe..b15675d 100644 --- a/src/main/kotlin/me/tech/mcchestui/GUI.kt +++ b/src/main/kotlin/me/tech/mcchestui/GUI.kt @@ -72,6 +72,12 @@ class GUI( */ var allowItemPlacement: Boolean = false + /** + * Allow for [ItemStack] to be shift-clicked into the [GUI]. + * Requires [allowItemPlacement] to be true to work. + */ + var allowShiftClick: Boolean = false + /** * Allow for [ItemStack] to be dragged within the [GUI]. */ diff --git a/src/main/kotlin/me/tech/mcchestui/listeners/item/GUIItemPlaceListener.kt b/src/main/kotlin/me/tech/mcchestui/listeners/item/GUIItemPlaceListener.kt index 73834b2..ae0d69c 100644 --- a/src/main/kotlin/me/tech/mcchestui/listeners/item/GUIItemPlaceListener.kt +++ b/src/main/kotlin/me/tech/mcchestui/listeners/item/GUIItemPlaceListener.kt @@ -2,11 +2,11 @@ package me.tech.mcchestui.listeners.item import me.tech.mcchestui.GUI import me.tech.mcchestui.listeners.GUIEventListener -import org.bukkit.Material import org.bukkit.entity.Player import org.bukkit.event.EventHandler import org.bukkit.event.inventory.InventoryAction import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.event.inventory.InventoryMoveItemEvent internal class GUIItemPlaceListener(gui: GUI) : GUIEventListener(gui) { @EventHandler @@ -26,7 +26,7 @@ internal class GUIItemPlaceListener(gui: GUI) : GUIEventListener(gui) { && isShiftClick && !gui.isBukkitInventory(clickedInventory) // make sure its incoming. ) { - if(!gui.allowItemPlacement) { + if(!gui.allowItemPlacement || !gui.allowShiftClick) { isCancelled = true return } @@ -42,17 +42,20 @@ internal class GUIItemPlaceListener(gui: GUI) : GUIEventListener(gui) { return } - val guiSlot = gui.slots.getOrNull(slot) - if(guiSlot != null) { - if(!guiSlot.allowPickup) { - isCancelled = true - return + val originatesFromPlayerInventory = !gui.isBukkitInventory(clickedInventory) + if(!originatesFromPlayerInventory) { + val guiSlot = gui.slots.getOrNull(slot) + if(guiSlot != null) { + if(!guiSlot.allowPickup) { + isCancelled = true + return + } } } - val itemStack = cursor + val itemStack = (if(isShiftClick) currentItem else cursor) ?: return - if(itemStack.type == Material.AIR) { + if(itemStack.type.isEmpty) { return }