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

Commit 2cb6717

Browse files
authored
Merge pull request #14 from BakaAless/dev
🔀 Merge pull request #14
2 parents 346cb0b + 535c581 commit 2cb6717

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.apache.tools.ant.filters.ReplaceTokens
2-
31
plugins {
42
id 'java'
53
id 'idea'

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

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,17 @@ public void forceStop(final JavaPlugin plugin) {
8383
synchronized void add(final InventoryAPI inv) {
8484
this.inventories.add(inv);
8585
if (this.inventories.size() == 1)
86-
start();
86+
this.start();
8787
}
8888

8989
synchronized void remove(final InventoryAPI inv) {
9090
this.inventories.remove(inv);
9191
if (this.inventories.size() == 0)
92-
stop();
92+
this.stop();
93+
}
94+
95+
synchronized int getStep() {
96+
return this.step;
9397
}
9498

9599
}

0 commit comments

Comments
 (0)