Skip to content
This repository was archived by the owner on Jul 24, 2021. It is now read-only.

Commit 35948bd

Browse files
authored
✨ Added click function consumer (#16)
1 parent 2c568db commit 35948bd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/main/java/fr/bakaaless/api/inventory/InventoryAPI.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class InventoryAPI implements Listener {
3333
private List<ItemAPI> items;
3434
private Consumer<InventoryAPI> function;
3535
private Consumer<InventoryCloseEvent> closeEvent;
36+
private Consumer<InventoryClickEvent> clickEvent;
3637
private boolean interactionCancel;
3738
private boolean refreshed;
3839
private boolean build;
@@ -166,6 +167,16 @@ public InventoryAPI setCloseFunction(final Consumer<InventoryCloseEvent> functio
166167
return this;
167168
}
168169

170+
/**
171+
* Define the click function.
172+
* @param function A consumer, that will be triggered when the player will click in the inventory.
173+
* @return Your InventoryAPI object
174+
*/
175+
public InventoryAPI setClickFunction(final Consumer<InventoryClickEvent> function) {
176+
this.clickEvent = function;
177+
return this;
178+
}
179+
169180
/**
170181
* Enable interaction protection for your Inventory
171182
* @param interactionCancelled A boolean, to enable/disable
@@ -497,6 +508,8 @@ public void onInteract(final InventoryClickEvent e) {
497508
return;
498509
if (!e.getClickedInventory().equals(this.inventory))
499510
return;
511+
if (this.clickEvent != null)
512+
this.clickEvent.accept(e);
500513
e.setCancelled(this.interactionCancel);
501514
final AtomicBoolean slotRegister = new AtomicBoolean(false);
502515
this.items.forEach(itemAPI -> {

0 commit comments

Comments
 (0)