Class StorageMenu

java.lang.Object
me.tayebyassine.homestead.storage.StorageMenu
All Implemented Interfaces:
org.bukkit.event.Listener

public final class StorageMenu extends Object implements 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

    Constructors
    Constructor
    Description
    StorageMenu(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 Type
    Method
    Description
    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.
    void
    Force-close this menu, unregister all listeners, and close the inventory if it is still open.
    org.bukkit.entity.Player
    Get the player viewing this menu.
    long
    Get the unique region ID this menu is associated with.
    boolean
    Whether this menu is still open and valid for interaction.
    void
    onInventoryClick(org.bukkit.event.inventory.InventoryClickEvent event)
     
    void
    onInventoryClose(org.bukkit.event.inventory.InventoryCloseEvent event)
     
    void
    onInventoryDrag(org.bukkit.event.inventory.InventoryDragEvent event)
     
    void
    onPlayerQuit(org.bukkit.event.player.PlayerQuitEvent event)
     
    void
    Open the inventory for the player and register it with the inventory manager.
    void
    Refresh the entire inventory display from the current storage state.
    void
    updateSlot(int slot, org.bukkit.inventory.ItemStack item)
    Update a single slot in the display.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • StorageMenu

      public StorageMenu(org.bukkit.entity.Player player, long regionId, String title, int size)
      Create and open a new storage menu for the given player.
      Parameters:
      player - the player viewing the storage
      regionId - the unique region ID
      title - the inventory title shown to the player
      size - 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:
      true if 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 index
      item - the item to show, or null to 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 index
      itemStack - the item to display
      callback - the click callback, or null for 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)