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

Commit 535c581

Browse files
committed
✨ Add a close consumer
1 parent 3c11b05 commit 535c581

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class InventoryAPI implements Listener {
3232
private InventoryType type;
3333
private List<ItemAPI> items;
3434
private Consumer<InventoryAPI> function;
35+
private Consumer<InventoryCloseEvent> closeEvent;
3536
private boolean interactionCancel;
3637
private boolean refreshed;
3738
private boolean build;
@@ -155,6 +156,16 @@ public InventoryAPI setFunction(final Consumer<InventoryAPI> function) {
155156
return this;
156157
}
157158

159+
/**
160+
* Define the close function.
161+
* @param function A consumer, that will be triggered when the player will close the inventory.
162+
* @return Your InventoryAPI object
163+
*/
164+
public InventoryAPI setCloseFunction(final Consumer<InventoryCloseEvent> function) {
165+
this.closeEvent = function;
166+
return this;
167+
}
168+
158169
/**
159170
* Enable interaction protection for your Inventory
160171
* @param interactionCancelled A boolean, to enable/disable
@@ -216,12 +227,20 @@ Inventory getInventory() {
216227

217228
/**
218229
* Get the consumer of the refresh task of your Inventory.
219-
* @return A consumer, that correspond to the refresh task.
230+
* @return A consumer, that corresponds to the refresh task.
220231
*/
221232
public Consumer<InventoryAPI> getFunction() {
222233
return function;
223234
}
224235

236+
/**
237+
* Get the consumer which will be triggered when the player will close the inventory.
238+
* @return A consumer, that corresponds to close event.
239+
*/
240+
public Consumer<InventoryCloseEvent> getCloseEvent() {
241+
return closeEvent;
242+
}
243+
225244
/**
226245
* Get the interactionCancelled boolean.
227246
* @return A boolean, true if interaction protection is enabled, else false.
@@ -446,6 +465,7 @@ public void stop() {
446465
if (this.refreshed)
447466
Scheduler.getInstance().remove(this);
448467
this.inventory = null;
468+
this.build = false;
449469
}
450470

451471
private Inventory generate() {
@@ -463,6 +483,7 @@ public void onClose(final InventoryCloseEvent e) {
463483
return;
464484
if (e.getInventory().getHolder() == null) {
465485
this.stop();
486+
this.closeEvent.accept(e);
466487
}
467488
}
468489

0 commit comments

Comments
 (0)