Skip to content

Commit 66aa972

Browse files
committed
feature: Add ClickContext#interact to allow determining if the click is from an interact event
1 parent d217732 commit 66aa972

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

interfaces/src/main/kotlin/com/noxcrew/interfaces/InterfacesListeners.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
252252
val isPlayerInventory = (event.clickedInventory ?: event.inventory).holder is Player
253253

254254
// Run base click handling
255-
if (handleClick(view, clickedPoint, event.click, event.hotbarButton, isPlayerInventory)) {
255+
if (handleClick(view, clickedPoint, event.click, event.hotbarButton, isPlayerInventory, false)) {
256256
event.isCancelled = true
257257
}
258258

@@ -415,7 +415,7 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
415415
return
416416
}
417417

418-
if (handleClick(view, clickedPoint, click, -1, true)) {
418+
if (handleClick(view, clickedPoint, click, -1, isPlayerInventory = true, interact = true)) {
419419
// Support modern behavior where we don't interfere with block interactions
420420
if (view.builder.onlyCancelItemInteraction) {
421421
event.setUseItemInHand(Event.Result.DENY)
@@ -557,7 +557,8 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
557557
clickedPoint: GridPoint,
558558
click: ClickType,
559559
slot: Int,
560-
isPlayerInventory: Boolean
560+
isPlayerInventory: Boolean,
561+
interact: Boolean
561562
): Boolean {
562563
// Determine the type of click, if nothing was clicked we allow it
563564
val raw = view.pane.getRaw(clickedPoint)
@@ -581,7 +582,7 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
581582
view.isProcessingClick = true
582583

583584
// Forward this click to all pre-processors
584-
val clickContext = ClickContext(view.player, view, click, slot)
585+
val clickContext = ClickContext(view.player, view, click, slot, interact)
585586
view.builder.clickPreprocessors
586587
.forEach { handler -> ClickHandler.process(handler, clickContext) }
587588

interfaces/src/main/kotlin/com/noxcrew/interfaces/click/ClickContext.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ public data class ClickContext(
1313
/** The type of click that was performed. */
1414
public val type: ClickType,
1515
/** The hot bar slot pressed between 0-8 if [type] is [ClickType.NUMBER_KEY], or `-1` otherwise. */
16-
public val slot: Int
16+
public val slot: Int,
17+
/** Whether the click was fired from an interact event (not from an open inventory). */
18+
public val interact: Boolean
1719
)

0 commit comments

Comments
 (0)