Skip to content

Commit b40d48d

Browse files
committed
✨ Add preClose method to IMenu for handling actions before canvas data is erased
1 parent 3573a00 commit b40d48d

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/main/java/com/marcusslover/plus/lib/item/IMenu.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ public interface IMenu extends ISendable<IMenu> {
1717
void open(@NotNull Canvas ctx, @NotNull Player player);
1818

1919
/**
20-
* Called when the menu is closed.
20+
* Called right before the canvas data is erased. You may use the menuUpdateContext here.
21+
*
22+
* @param ctx the canvas
23+
* @param player the player
24+
*/
25+
default void preClose(@NotNull Canvas ctx, @NotNull Player player) {
26+
// nothing here
27+
}
28+
29+
/**
30+
* Called when the menu is closed. At this point using menuUpdateContext is not possible.
2131
*
2232
* @param ctx the canvas
2333
* @param player the player

src/main/java/com/marcusslover/plus/lib/item/MenuManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public void onClose(InventoryCloseEvent event) {
7373
}
7474

7575
Menu menu = canvas.assosiatedMenu();
76+
menu.preClose(canvas, player); // call the preClose method so developers can handle it
7677
Canvas remove = menu.canvasMap().remove(player.getUniqueId());
7778
if (remove != null) {
7879
remove.clear(); // help the gc

0 commit comments

Comments
 (0)