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 Summary
Modifier and TypeMethodDescriptionReturns the current inventory used in this menu.static InventoryMenu
of
(ViewableInventory inventory) Creates a new InventoryMenu based on given inventory.open
(ServerPlayer player) Opens this menu for givenplayer
.void
registerChange
(SlotChangeHandler handler) Registers a change callback.void
registerClick
(ClickHandler handler) Registers a click callback.void
registerClose
(CloseHandler handler) Registers a callback for when this menu is closed.void
registerHandler
(InventoryCallbackHandler handler) Registers click callbacks.void
registerKeySwap
(KeySwapHandler handler) Registers a key-swap click callback.void
registerSlotClick
(SlotClickHandler handler) Registers a slot click callback.void
setCurrentInventory
(ViewableInventory inventory) Sets a new inventory.setReadOnly
(boolean readOnly) Sets the readonly mode for this menu.setReadOnly
(Slot slot, boolean readOnly) Sets theSlot
readonly mode for this menu.void
Sets the title of this menu.title()
Returns the title of this menu if set.void
Unregisters all callback handlers.
-
Method Details
-
of
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
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
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.
-
unregisterAll
void unregisterAll()Unregisters all callback handlers. -
setReadOnly
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
Sets theSlot
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 changedreadOnly
- 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 givenplayer
.- Parameters:
player
- the player.- Returns:
- the opened Container.
-