@@ -36,6 +36,7 @@ public final class ChestInterface implements
3636 private final @ NonNull Component title ;
3737 private final boolean updates ;
3838 private final int updateDelay ;
39+ private final boolean cancelClicksInPlayerInventory ;
3940 private final @ NonNull ClickHandler <ChestPane , InventoryClickEvent , PlayerViewer , InventoryClickContext <ChestPane ,
4041 ChestView >> clickHandler ;
4142
@@ -48,6 +49,7 @@ public final class ChestInterface implements
4849 * @param closeHandlers the close handlers to apply
4950 * @param updates {@code true} if the interface is an updating interface
5051 * @param updateDelay the update delay
52+ * @param cancelClicksInPlayerInventory whether to cancel clicks in the players inventory
5153 * @param clickHandler the handler to run on click
5254 */
5355 public ChestInterface (
@@ -57,6 +59,7 @@ public ChestInterface(
5759 final @ NonNull List <CloseHandler <ChestPane >> closeHandlers ,
5860 final boolean updates ,
5961 final int updateDelay ,
62+ final boolean cancelClicksInPlayerInventory ,
6063 final @ NonNull ClickHandler <ChestPane , InventoryClickEvent , PlayerViewer , InventoryClickContext <ChestPane ,
6164 ChestView >> clickHandler
6265 ) {
@@ -66,6 +69,7 @@ public ChestInterface(
6669 this .updates = updates ;
6770 this .updateDelay = updateDelay ;
6871 this .rows = rows ;
72+ this .cancelClicksInPlayerInventory = cancelClicksInPlayerInventory ;
6973 this .clickHandler = clickHandler ;
7074 }
7175
@@ -208,6 +212,14 @@ public int updateDelay() {
208212 return this .updateDelay ;
209213 }
210214
215+ /**
216+ * Whether interfaces should cancel events that come from the players inventories.
217+ * @return true if it should cancel the events
218+ */
219+ public boolean cancelClicksInPlayerInventory () {
220+ return this .cancelClicksInPlayerInventory ;
221+ }
222+
211223 /**
212224 * A class that builds a chest interface.
213225 */
@@ -243,6 +255,8 @@ public static final class Builder implements Interface.Builder<ChestPane, Player
243255 */
244256 private final int updateDelay ;
245257
258+ private final boolean cancelClicksInPlayerInventory ;
259+
246260 /**
247261 * The top click handler.
248262 */
@@ -259,6 +273,7 @@ public Builder() {
259273 this .title = Component .empty ();
260274 this .updates = false ;
261275 this .updateDelay = 1 ;
276+ this .cancelClicksInPlayerInventory = false ;
262277 this .clickHandler = ClickHandler .cancel ();
263278 }
264279
@@ -269,6 +284,7 @@ private Builder(
269284 final @ NonNull Component title ,
270285 final boolean updates ,
271286 final int updateDelay ,
287+ final boolean cancelClicksInPlayerInventory ,
272288 final @ NonNull ClickHandler <ChestPane , InventoryClickEvent , PlayerViewer , InventoryClickContext <ChestPane ,
273289 ChestView >> clickHandler
274290 ) {
@@ -278,6 +294,7 @@ private Builder(
278294 this .title = title ;
279295 this .updates = updates ;
280296 this .updateDelay = updateDelay ;
297+ this .cancelClicksInPlayerInventory = cancelClicksInPlayerInventory ;
281298 this .clickHandler = clickHandler ;
282299 }
283300
@@ -304,6 +321,7 @@ public int rows() {
304321 this .title ,
305322 this .updates ,
306323 this .updateDelay ,
324+ this .cancelClicksInPlayerInventory ,
307325 this .clickHandler
308326 );
309327 }
@@ -331,6 +349,7 @@ public int rows() {
331349 title ,
332350 this .updates ,
333351 this .updateDelay ,
352+ this .cancelClicksInPlayerInventory ,
334353 this .clickHandler
335354 );
336355 }
@@ -352,6 +371,7 @@ public int rows() {
352371 this .title ,
353372 this .updates ,
354373 this .updateDelay ,
374+ this .cancelClicksInPlayerInventory ,
355375 this .clickHandler
356376 );
357377 }
@@ -384,6 +404,7 @@ public int rows() {
384404 this .title ,
385405 this .updates ,
386406 this .updateDelay ,
407+ this .cancelClicksInPlayerInventory ,
387408 this .clickHandler
388409 );
389410 }
@@ -424,6 +445,7 @@ InventoryClickContext<ChestPane, ChestView>> clickHandler() {
424445 this .title ,
425446 this .updates ,
426447 this .updateDelay ,
448+ this .cancelClicksInPlayerInventory ,
427449 handler
428450 );
429451 }
@@ -443,6 +465,25 @@ InventoryClickContext<ChestPane, ChestView>> clickHandler() {
443465 this .title ,
444466 updates ,
445467 updateDelay ,
468+ this .cancelClicksInPlayerInventory ,
469+ this .clickHandler
470+ );
471+ }
472+
473+ /**
474+ * Controls if the interface should stop items coming from the player's inventory.
475+ * @param cancelClicksInPlayerInventory true if it should stop items.
476+ * @return new builder instance
477+ */
478+ public @ NonNull Builder cancelClicksInPlayerInventory (final boolean cancelClicksInPlayerInventory ) {
479+ return new Builder (
480+ this .transformsList ,
481+ this .closeHandlerList ,
482+ this .rows ,
483+ this .title ,
484+ this .updates ,
485+ this .updateDelay ,
486+ cancelClicksInPlayerInventory ,
446487 this .clickHandler
447488 );
448489 }
@@ -461,6 +502,7 @@ InventoryClickContext<ChestPane, ChestView>> clickHandler() {
461502 this .closeHandlerList ,
462503 this .updates ,
463504 this .updateDelay ,
505+ this .cancelClicksInPlayerInventory ,
464506 this .clickHandler
465507 );
466508 }
0 commit comments