Class StorageMenu
java.lang.Object
me.tayebyassine.homestead.storage.StorageMenu
- All Implemented Interfaces:
org.bukkit.event.Listener
A player-specific inventory menu backed by a
SharedStorage.
Handles all click/drag interactions, synchronizes changes back to the
storage, and keeps the view updated when other players modify the same
storage through StorageManager.
-
Constructor Summary
ConstructorsConstructorDescriptionStorageMenu(org.bukkit.entity.Player player, long regionId, String title, int size) Create and open a new storage menu for the given player. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddItem(int slot, org.bukkit.inventory.ItemStack itemStack, BiConsumer<org.bukkit.entity.Player, org.bukkit.event.inventory.InventoryClickEvent> callback) Add a static item with an optional click callback to the inventory.voidForce-close this menu, unregister all listeners, and close the inventory if it is still open.org.bukkit.entity.PlayerGet the player viewing this menu.longGet the unique region ID this menu is associated with.booleanisValid()Whether this menu is still open and valid for interaction.voidonInventoryClick(org.bukkit.event.inventory.InventoryClickEvent event) voidonInventoryClose(org.bukkit.event.inventory.InventoryCloseEvent event) voidonInventoryDrag(org.bukkit.event.inventory.InventoryDragEvent event) voidonPlayerQuit(org.bukkit.event.player.PlayerQuitEvent event) voidopen()Open the inventory for the player and register it with the inventory manager.voidRefresh the entire inventory display from the current storage state.voidupdateSlot(int slot, org.bukkit.inventory.ItemStack item) Update a single slot in the display.
-
Constructor Details
-
StorageMenu
Create and open a new storage menu for the given player.- Parameters:
player- the player viewing the storageregionId- the unique region IDtitle- the inventory title shown to the playersize- the inventory size (must be a valid Bukkit size)
-
-
Method Details
-
getPlayer
public org.bukkit.entity.Player getPlayer()Get the player viewing this menu.- Returns:
- the player
-
getRegionId
public long getRegionId()Get the unique region ID this menu is associated with.- Returns:
- the region ID
-
isValid
public boolean isValid()Whether this menu is still open and valid for interaction.- Returns:
trueif the menu is open and the player is online
-
refreshDisplay
public void refreshDisplay()Refresh the entire inventory display from the current storage state. -
updateSlot
public void updateSlot(int slot, org.bukkit.inventory.ItemStack item) Update a single slot in the display.- Parameters:
slot- the slot indexitem- the item to show, ornullto clear
-
open
public void open()Open the inventory for the player and register it with the inventory manager. -
forceClose
public void forceClose()Force-close this menu, unregister all listeners, and close the inventory if it is still open. -
addItem
public void addItem(int slot, org.bukkit.inventory.ItemStack itemStack, BiConsumer<org.bukkit.entity.Player, org.bukkit.event.inventory.InventoryClickEvent> callback) Add a static item with an optional click callback to the inventory.- Parameters:
slot- the slot indexitemStack- the item to displaycallback- the click callback, ornullfor no action
-
onInventoryClick
public void onInventoryClick(org.bukkit.event.inventory.InventoryClickEvent event) -
onInventoryDrag
public void onInventoryDrag(org.bukkit.event.inventory.InventoryDragEvent event) -
onInventoryClose
public void onInventoryClose(org.bukkit.event.inventory.InventoryCloseEvent event) -
onPlayerQuit
public void onPlayerQuit(org.bukkit.event.player.PlayerQuitEvent event)
-