Skip to content

Commit

Permalink
✨MenuManager global generic click
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusSlover committed May 28, 2024
1 parent 7b35a45 commit b96c4e0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/java/com/marcusslover/plus/lib/item/MenuManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public final class MenuManager {
private final @NotNull EventReference<InventoryCloseEvent> closeEvent;
private final @NotNull EventReference<InventoryClickEvent> clickEvent;

// Global click context
private @Nullable Canvas.GenericClick genericClick = null;

public MenuManager(@NotNull Plugin plugin) {
this.plugin = plugin;
this.closeEvent = Events.listen(InventoryCloseEvent.class).handler(event -> {
Expand Down Expand Up @@ -80,6 +83,15 @@ public MenuManager(@NotNull Plugin plugin) {

Item item = Item.of(event.getCurrentItem());

// handle the generic click context (global)
if (this.genericClick != null) {
try {
this.genericClick.onClick((Player) event.getWhoClicked(), item, event, canvas);
} catch (Throwable e) {
Bukkit.getLogger().warning(e.getMessage());
}
}

Canvas.ClickContext genericClick = canvas.genericClick();
if (genericClick != null) {
Canvas.ButtonClick buttonClick = genericClick.click();
Expand Down Expand Up @@ -342,6 +354,16 @@ private void updateInventory(@NotNull Player player, @NotNull Inventory inventor
return this.menus;
}

/**
* Sets the generic click context, this will affect all menus.
* @param context the context
* @return the manager
*/
public @NotNull MenuManager genericClick(@Nullable Canvas.GenericClick context) {
this.genericClick = context;
return this;
}

/**
* Clears the menus.
* Shutdown the manager.
Expand Down

0 comments on commit b96c4e0

Please sign in to comment.