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 Link icon

    • of Link icon

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

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

      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 Link icon

      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 Link icon

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

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

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

      void unregisterAll()
      Unregisters all callback handlers.
    • setReadOnly Link icon

      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 Link icon

      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 Link icon

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