Skip to content

Commit

Permalink
feat: support checking player inventory click
Browse files Browse the repository at this point in the history
  • Loading branch information
DebitCardz committed Aug 19, 2024
1 parent c71cc89 commit 4142002
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 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.4"
version = "1.5.5"

repositories {
mavenCentral()
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/me/tech/mcchestui/GUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal class GUIHotbarListener(gui: GUI) : GUIEventListener(gui) {
currentItem
} ?: return

if(itemStack.type == Material.AIR) {
if(itemStack.type.isEmpty) {
return
}

Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 4142002

Please sign in to comment.