Class MenuEvents<M extends Menu<M>>

java.lang.Object
com.kamikazejam.kamicommon.menu.api.struct.MenuEvents<M>

public class MenuEvents<M extends Menu<M>> extends Object
A container for all the events that can be added to a Menu.
The underlying Map can be accessed directly with getters for each callback type.
Additional helper methods are provided to add callbacks.
  • Constructor Details

    • MenuEvents

      public MenuEvents()
  • Method Details

    • addClickPredicate

      @NotNull public @NotNull MenuEvents<M> addClickPredicate(@NotNull @NotNull Predicate<InventoryClickEvent> predicate)
      Add a predicate on InventoryClickEvent that must pass for the click handlers on that slot to be executed.
      This applies to the Menu's inventory only, not the player's inventory.
      For adding a predicate for player inventory clicks, use addPlayerClickPredicate(Predicate)
      Returns:
      this MenuEvents object for chaining
    • addClickPredicate

      @NotNull public @NotNull MenuEvents<M> addClickPredicate(@NotNull @NotNull String id, @NotNull @NotNull Predicate<InventoryClickEvent> predicate)
      Add a predicate on InventoryClickEvent that must pass for the click handlers on that slot to be executed.
      This applies to the Menu's inventory only, not the player's inventory.
      For adding a predicate for player inventory clicks, use addPlayerClickPredicate(String, Predicate)
      Parameters:
      id - The ID to associate with this predicate for later removal
      Returns:
      this MenuEvents object for chaining
    • removeClickPredicate

      public boolean removeClickPredicate(@NotNull @NotNull String id)
      Remove a click predicate by ID
    • addCloseCallback

      @NotNull public @NotNull MenuEvents<M> addCloseCallback(@NotNull @NotNull MenuCloseCallback callback)
      Add a callback that runs when the inventory is closed, with access to Player and InventoryCloseEvent.
      Returns:
      this MenuEvents object for chaining
    • addCloseCallback

      @NotNull public @NotNull MenuEvents<M> addCloseCallback(@NotNull @NotNull String id, @NotNull @NotNull MenuCloseCallback callback)
      Add a callback that runs when the inventory is closed, with access to Player and InventoryCloseEvent.
      Parameters:
      id - The ID to associate with this callback for later removal
      Returns:
      this MenuEvents object for chaining
    • removeCloseCallback

      public boolean removeCloseCallback(@NotNull @NotNull String id)
      Remove a close callback by ID
    • addPostCloseCallback

      @NotNull public @NotNull MenuEvents<M> addPostCloseCallback(@NotNull @NotNull MenuPostCloseCallback<M> callback)
      Add a callback that runs 1 tick after the inventory is closed, with access to Player.
      Note: This 1 tick delay is technically enough time for a player to log out. This event is guaranteed to run, but the player may not be online.
      This is the method you must use for Menus that you want to re-open when closed. Using addCloseCallback(MenuCloseCallback) will cause recursion.
      Returns:
      this MenuEvents object for chaining
    • addPostCloseCallback

      @NotNull public @NotNull MenuEvents<M> addPostCloseCallback(@NotNull @NotNull String id, @NotNull @NotNull MenuPostCloseCallback<M> callback)
      Add a callback that runs 1 tick after the inventory is closed, with access to Player.
      Note: This 1 tick delay is technically enough time for a player to log out. This event is guaranteed to run, but the player may not be online.
      This is the method you must use for Menus that you want to re-open when closed. Using addCloseCallback(String, MenuCloseCallback) will cause recursion.
      Parameters:
      id - The ID to associate with this callback for later removal
      Returns:
      this MenuEvents object for chaining
    • removePostCloseCallback

      public boolean removePostCloseCallback(@NotNull @NotNull String id)
      Remove a post-close callback by ID
    • addOpenCallback

      @NotNull public @NotNull MenuEvents<M> addOpenCallback(@Nullable @Nullable MenuOpenCallback menuOpen)
      Add a callback that runs when the inventory is opened.
      Returns:
      this MenuEvents object for chaining
    • addOpenCallback

      @NotNull public @NotNull MenuEvents<M> addOpenCallback(@NotNull @NotNull String id, @Nullable @Nullable MenuOpenCallback menuOpen)
      Add a callback that runs when the inventory is opened.
      Parameters:
      id - The ID to associate with this callback for later removal
      Returns:
      this MenuEvents object for chaining
    • removeOpenCallback

      public boolean removeOpenCallback(@NotNull @NotNull String id)
      Remove an open callback by ID
    • addPlayerSlotClick

      @NotNull public @NotNull MenuEvents<M> addPlayerSlotClick(int slot, @NotNull @NotNull PlayerSlotClick<M> click)
      Listen to a player inventory click. (at a specific slot)
      Parameters:
      slot - The player inventory slot number to listen to.
      Returns:
      this MenuEvents object for chaining.
    • addPlayerSlotClick

      @NotNull public @NotNull MenuEvents<M> addPlayerSlotClick(int slot, @NotNull @NotNull String id, @NotNull @NotNull PlayerSlotClick<M> click)
      Listen to a player inventory click. (at a specific slot)
      Parameters:
      slot - The player inventory slot number to listen to.
      id - The ID to associate with this click handler for later removal
      Returns:
      this MenuEvents object for chaining.
    • removePlayerSlotClick

      public boolean removePlayerSlotClick(@NotNull @NotNull String id)
      Remove a player inventory click by ID
    • addPlayerSlotClick

      @NotNull @Deprecated public @NotNull MenuEvents<M> addPlayerSlotClick(@NotNull @NotNull PlayerSlotClick<M> click)
      Deprecated.
      Use addPlayerInvClick(PlayerSlotClick) instead. This method will be removed in a future release.
      Adds a click event for a player slot.
      Parameters:
      click - The PlayerSlotClick event to add.
      Returns:
      This MenuEvents instance.
    • addPlayerInvClick

      public MenuEvents<M> addPlayerInvClick(@NotNull @NotNull PlayerSlotClick<M> click)
      Listen to ALL player inventory clicks. (in any slot)
      Parameters:
      click - The callback to run when a player clicks a slot in their inventory.
      Returns:
      this MenuEvents object for chaining.
    • addPlayerInvClick

      public MenuEvents<M> addPlayerInvClick(@NotNull @NotNull String id, @NotNull @NotNull PlayerSlotClick<M> click)
      Listen to ALL player inventory clicks. (in any slot)
      Parameters:
      id - The ID to associate with this click handler for later removal
      click - The callback to run when a player clicks a slot in their inventory.
      Returns:
      this MenuEvents object for chaining.
    • removePlayerInvClick

      public boolean removePlayerInvClick(@NotNull @NotNull String id)
      Remove a player inventory click by ID
    • addPlayerClickPredicate

      @NotNull public @NotNull MenuEvents<M> addPlayerClickPredicate(@NotNull @NotNull Predicate<InventoryClickEvent> predicate)
      Add a predicate on InventoryClickEvent that must pass for the click handlers on that slot to be executed.
      This applies to the Player's inventory only, not the menu's inventory.
      For adding a predicate for the Menu inventory clicks, use addClickPredicate(Predicate)
      Returns:
      this MenuEvents object for chaining
    • addPlayerClickPredicate

      @NotNull public @NotNull MenuEvents<M> addPlayerClickPredicate(@NotNull @NotNull String id, @NotNull @NotNull Predicate<InventoryClickEvent> predicate)
      Add a predicate on InventoryClickEvent that must pass for the click handlers on that slot to be executed.
      This applies to the Player's inventory only, not the menu's inventory.
      For adding a predicate for the Menu inventory clicks, use addClickPredicate(String, Predicate)
      Parameters:
      id - The ID to associate with this predicate for later removal
      Returns:
      this MenuEvents object for chaining
    • removePlayerClickPredicate

      public boolean removePlayerClickPredicate(@NotNull @NotNull String id)
      Remove a player inventory click predicate by ID
    • addDragPredicate

      @NotNull public @NotNull MenuEvents<M> addDragPredicate(@NotNull @NotNull Predicate<InventoryDragEvent> predicate)
      Add a predicate on InventoryDragEvent that must pass for drag operations on menu slots to proceed.
      This applies to the Menu's inventory only.
      For adding a predicate for player inventory drags, use addPlayerDragPredicate(Predicate)
      Returns:
      this MenuEvents object for chaining
    • addDragPredicate

      @NotNull public @NotNull MenuEvents<M> addDragPredicate(@NotNull @NotNull String id, @NotNull @NotNull Predicate<InventoryDragEvent> predicate)
      Add a predicate on InventoryDragEvent that must pass for drag operations on menu slots to proceed.
      This applies to the Menu's inventory only.
      For adding a predicate for player inventory drags, use addPlayerDragPredicate(String, Predicate)
      Parameters:
      id - The ID to associate with this predicate for later removal
      Returns:
      this MenuEvents object for chaining
    • removeDragPredicate

      public boolean removeDragPredicate(@NotNull @NotNull String id)
      Remove a drag predicate by ID
    • addPlayerDragPredicate

      @NotNull public @NotNull MenuEvents<M> addPlayerDragPredicate(@NotNull @NotNull Predicate<InventoryDragEvent> predicate)
      Add a predicate on InventoryDragEvent that must pass for drag operations in the player's inventory.
      This only applies when the drag does NOT affect any menu slots.
      For adding a predicate for menu inventory drags, use addDragPredicate(Predicate)
      Returns:
      this MenuEvents object for chaining
    • addPlayerDragPredicate

      @NotNull public @NotNull MenuEvents<M> addPlayerDragPredicate(@NotNull @NotNull String id, @NotNull @NotNull Predicate<InventoryDragEvent> predicate)
      Add a predicate on InventoryDragEvent that must pass for drag operations in the player's inventory.
      This only applies when the drag does NOT affect any menu slots.
      For adding a predicate for menu inventory drags, use addDragPredicate(String, Predicate)
      Parameters:
      id - The ID to associate with this predicate for later removal
      Returns:
      this MenuEvents object for chaining
    • removePlayerDragPredicate

      public boolean removePlayerDragPredicate(@NotNull @NotNull String id)
      Remove a player inventory drag predicate by ID
    • addDragCallback

      @NotNull public @NotNull MenuEvents<M> addDragCallback(@NotNull @NotNull MenuDragCallback callback)
      Add a callback that runs when a drag event affects menu slots (and is not cancelled).
      Returns:
      this MenuEvents object for chaining
    • addDragCallback

      @NotNull public @NotNull MenuEvents<M> addDragCallback(@NotNull @NotNull String id, @NotNull @NotNull MenuDragCallback callback)
      Add a callback that runs when a drag event affects menu slots (and is not cancelled).
      Parameters:
      id - The ID to associate with this callback for later removal
      Returns:
      this MenuEvents object for chaining
    • removeDragCallback

      public boolean removeDragCallback(@NotNull @NotNull String id)
      Remove a drag callback by ID
    • copy

      @NotNull public @NotNull MenuEvents<M> copy()