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 Detail

      • 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 closed and reopened with the new title.

        Parameters:
        title - the new title.
      • title

        Optional<Component> title()
        Returns the title of this menu if set.
        Returns:
        the title of this menu if set.
      • 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