Interface InventoryMenu


public interface InventoryMenu
Helper for Menus based on Inventories.

This helper provides simple callbacks that can be used instead of listening to inventory events.

InventoryMenus are by default readonly and automatically prevent any changes made by players in the menu.

  • Method Details

    • of

      static InventoryMenu of(ViewableInventory inventory)
      Creates a new InventoryMenu based on given inventory.
      Parameters:
      inventory - the inventory
      Returns:
      the new menu.
    • inventory

      ViewableInventory inventory()
      Returns the current inventory used in this menu.
      Returns:
      the current inventory
    • setCurrentInventory

      void setCurrentInventory(ViewableInventory inventory)
      Sets a new inventory. If the ContainerType does not change the inventory will be swapped out silently.

      If the ContainerType is different all existing callbacks are cleared and open menus are closed and reopened with the new inventory.

      Parameters:
      inventory - the new inventory
    • setTitle

      void setTitle(Component title)
      Sets the title of this menu.

      Any open menus are updated with the new title.

      Parameters:
      title - the new title.
    • title

      Returns the title of this menu if set.
      Returns:
      the title of this menu if set.
    • registerHandler

      void registerHandler(InventoryCallbackHandler handler)
      Registers click callbacks. Unregisters previously registered handler of the same type.

      Return false in the handler to prevent changes.

      Possible handlers: ClickHandler, SlotClickHandler, KeySwapHandler, SlotChangeHandler, CloseHandler

      Parameters:
      handler - the handler
    • registerClick

      void registerClick(ClickHandler handler)
      Registers a click callback. Unregisters previously registered handler of the same type.

      Return false in the handler to prevent changes.

      Parameters:
      handler - the handler
    • registerSlotClick

      void registerSlotClick(SlotClickHandler handler)
      Registers a slot click callback. Unregisters previously registered handler of the same type.

      Return false in the handler to prevent changes.

      Parameters:
      handler - the handler
    • registerKeySwap

      void registerKeySwap(KeySwapHandler handler)
      Registers a key-swap click callback. Unregisters previously registered handler of the same type.

      Return false in the handler to prevent changes.

      Parameters:
      handler - the handler
    • registerChange

      void registerChange(SlotChangeHandler handler)
      Registers a change callback. Unregisters previously registered SlotChangeHandler.

      You can override the behaviour of setReadOnly(boolean) with this.

      Return false in the handler to prevent changes.

      Parameters:
      handler - the callback handler
    • registerClose

      void registerClose(CloseHandler handler)
      Registers a callback for when this menu is closed. Unregisters previously registered handler.
      Parameters:
      handler - the callback handler
    • unregisterAll

      void unregisterAll()
      Unregisters all callback handlers.
    • setReadOnly

      InventoryMenu setReadOnly(boolean readOnly)
      Sets the readonly mode for this menu.

      By default this is true and cancels any change in menu.

      Parameters:
      readOnly - whether to make the menu readonly or not.
      Returns:
      this menu
    • setReadOnly

      InventoryMenu setReadOnly(Slot slot, boolean readOnly)
      Sets the Slot readonly mode for this menu. By default, uses the menus current readonly mode. This can be used to override per slot.
      Parameters:
      slot - the slot which readonly mode is changed
      readOnly - whether to make the slot readonly or not.
      Returns:
      this menu
      Throws:
      IllegalArgumentException - if the slot is not part of the menu
    • open

      Opens this menu for given player.
      Parameters:
      player - the player.
      Returns:
      the opened Container.