Skip to content

Commit

Permalink
* Added live updating ability to Menu.Paginated
Browse files Browse the repository at this point in the history
  • Loading branch information
Hempfest committed Jun 7, 2021
1 parent 8f613e5 commit 66bcda5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,17 @@ protected Paginated(PaginatedBuilder<T> builder) {
*/
public void open(Player p) {
this.builder.INVENTORY = Bukkit.createInventory(null, this.builder.SIZE, this.builder.TITLE.replace("{PAGE}", "" + (this.builder.PAGE + 1)).replace("{MAX}", "" + this.builder.getMaxPages()));
this.builder.INVENTORY.setMaxStackSize(1);
if (this.builder.LIVE) {

this.builder.INVENTORY.setMaxStackSize(1);
if (this.builder.TASK.containsKey(p)) {
this.builder.TASK.get(p).cancelTask();
}

this.builder.TASK.put(p, Schedule.async(() -> {
Schedule.sync(this.builder::adjust).run();
Schedule.sync(() -> {
this.builder.INVENTORY.clear();
this.builder.adjust();
}).run();
}));
this.builder.TASK.get(p).repeat(1, 5);
Schedule.sync(() -> p.openInventory(this.builder.getInventory())).waitReal(2);
Expand Down Expand Up @@ -228,7 +230,12 @@ public void liven(Player p, int delay, int period) {
this.builder.TASK.get(p).cancelTask();
}

Schedule.sync(this.builder::adjust).run();
this.builder.TASK.put(p, Schedule.async(() -> {
Schedule.sync(() -> {
this.builder.INVENTORY.clear();
this.builder.adjust();
}).run();
}));
this.builder.TASK.get(p).repeat(delay, period);
Schedule.sync(() -> p.openInventory(this.builder.getInventory())).waitReal(delay + 1);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,23 @@ public void sync() {
p.openInventory(builder.adjust().getInventory());
}

public void sync(int page, int delay, int period) {
public void sync(int delay, int period) {
this.builder.INVENTORY = Bukkit.createInventory(null, this.builder.SIZE, this.builder.TITLE.replace("{PAGE}", "" + (this.builder.PAGE + 1)).replace("{MAX}", "" + this.builder.getMaxPages()));
if (this.builder.LIVE) {

if (this.builder.LIVE) {
this.builder.INVENTORY.setMaxStackSize(1);
if (this.builder.TASK.containsKey(p)) {
this.builder.TASK.get(p).cancelTask();
}

this.builder.TASK.put(p, Schedule.async(() -> Schedule.sync(() -> this.builder.adjust(Math.min(page, this.builder.getMaxPages()))).run()));
this.builder.TASK.put(p, Schedule.async(() -> Schedule.sync(() -> {
this.builder.INVENTORY.clear();
this.builder.adjust();
}).run()));
this.builder.TASK.get(p).repeat(delay, period);
Schedule.sync(() -> p.openInventory(this.builder.getInventory())).waitReal(delay + 1);
} else {
p.openInventory(this.builder.adjust(Math.min(page, this.builder.getMaxPages())).getInventory());
p.openInventory(this.builder.adjust().getInventory());
}
}

Expand Down
Binary file modified out/artifacts/Labyrinth_jar/Labyrinth.jar
Binary file not shown.

0 comments on commit 66bcda5

Please sign in to comment.