Skip to content

Commit d664cc3

Browse files
committed
feat: experimental shift clicking
1 parent b431038 commit d664cc3

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ val githubActor = project.findProperty("gpr.user") as String? ?: System.getenv("
88
val githubToken = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
99

1010
group = "me.tech"
11-
version = "1.5.0"
11+
version = "1.5.3"
1212

1313
repositories {
1414
mavenCentral()

src/main/kotlin/me/tech/mcchestui/GUI.kt

+6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ class GUI(
7272
*/
7373
var allowItemPlacement: Boolean = false
7474

75+
/**
76+
* Allow for [ItemStack] to be shift-clicked into the [GUI].
77+
* Requires [allowItemPlacement] to be true to work.
78+
*/
79+
var allowShiftClick: Boolean = false
80+
7581
/**
7682
* Allow for [ItemStack] to be dragged within the [GUI].
7783
*/

src/main/kotlin/me/tech/mcchestui/listeners/item/GUIItemPlaceListener.kt

+12-9
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package me.tech.mcchestui.listeners.item
22

33
import me.tech.mcchestui.GUI
44
import me.tech.mcchestui.listeners.GUIEventListener
5-
import org.bukkit.Material
65
import org.bukkit.entity.Player
76
import org.bukkit.event.EventHandler
87
import org.bukkit.event.inventory.InventoryAction
98
import org.bukkit.event.inventory.InventoryClickEvent
9+
import org.bukkit.event.inventory.InventoryMoveItemEvent
1010

1111
internal class GUIItemPlaceListener(gui: GUI) : GUIEventListener(gui) {
1212
@EventHandler
@@ -26,7 +26,7 @@ internal class GUIItemPlaceListener(gui: GUI) : GUIEventListener(gui) {
2626
&& isShiftClick
2727
&& !gui.isBukkitInventory(clickedInventory) // make sure its incoming.
2828
) {
29-
if(!gui.allowItemPlacement) {
29+
if(!gui.allowItemPlacement || !gui.allowShiftClick) {
3030
isCancelled = true
3131
return
3232
}
@@ -42,17 +42,20 @@ internal class GUIItemPlaceListener(gui: GUI) : GUIEventListener(gui) {
4242
return
4343
}
4444

45-
val guiSlot = gui.slots.getOrNull(slot)
46-
if(guiSlot != null) {
47-
if(!guiSlot.allowPickup) {
48-
isCancelled = true
49-
return
45+
val originatesFromPlayerInventory = !gui.isBukkitInventory(clickedInventory)
46+
if(!originatesFromPlayerInventory) {
47+
val guiSlot = gui.slots.getOrNull(slot)
48+
if(guiSlot != null) {
49+
if(!guiSlot.allowPickup) {
50+
isCancelled = true
51+
return
52+
}
5053
}
5154
}
5255

53-
val itemStack = cursor
56+
val itemStack = (if(isShiftClick) currentItem else cursor)
5457
?: return
55-
if(itemStack.type == Material.AIR) {
58+
if(itemStack.type.isEmpty) {
5659
return
5760
}
5861

0 commit comments

Comments
 (0)