Skip to content

Commit

Permalink
feat: experimental shift clicking
Browse files Browse the repository at this point in the history
  • Loading branch information
DebitCardz committed Aug 18, 2024
1 parent b431038 commit d664cc3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/me/tech/mcchestui/GUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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].
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
}

Expand Down

0 comments on commit d664cc3

Please sign in to comment.