Class Menu

java.lang.Object
me.tayebyassine.homestead.gui.Menu
All Implemented Interfaces:
org.bukkit.event.Listener

public class Menu extends Object implements org.bukkit.event.Listener
Base menu class providing a builder-pattern API for creating non-paginated Bukkit inventory menus.

Supports button callbacks, item-only slots, fill-empty-slots, back button, and automatic self-registration as a Bukkit Listener. Each menu instance registers itself on build and unregisters on close.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Map<Integer, BiConsumer<org.bukkit.entity.Player, org.bukkit.event.inventory.InventoryClickEvent>>
     
    protected final org.bukkit.inventory.Inventory
     
    protected final String
     
    protected boolean
     
    protected final Homestead
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Menu(Menu.Builder<?> builder)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Menu.Builder<?>
    builder(String menuKey, int size)
    Creates a new builder for a menu with the given title key and size.
    static Menu.Builder<?>
    builder(String menuKey, int size, boolean passthrough)
    Creates a new builder with passthrough mode enabled or disabled.
    static Menu.Builder<?>
    builder(String menuKey, Placeholder placeholder, int size)
    Creates a new builder with a placeholder applied to the menu title.
    static Menu.Builder<?>
    builder(String menuKey, Placeholder placeholder, int size, boolean passthrough)
    Creates a new builder with a placeholder and passthrough mode.
    void
    Unregisters this menu as a Bukkit event listener.
    Fills all empty slots with the default empty slot item from MenuButtons.
    fillEmptySlots(org.bukkit.inventory.ItemStack filler)
    Fills all empty slots in the inventory with the given filler item.
    protected boolean
    isValidSlot(int slot)
    Checks whether the given slot index is within the valid range for this inventory.
    void
    onInventoryClick(org.bukkit.event.inventory.InventoryClickEvent event)
    Handles inventory click events, delegating registered button callbacks.
    void
    onInventoryClose(org.bukkit.event.inventory.InventoryCloseEvent event)
    Handles inventory close events, unregistering the player and destroying this menu.
    void
    open(org.bukkit.entity.Player player)
    Opens this menu for the specified player and registers the player with InventoryManager.
    setButton(int slot, org.bukkit.inventory.ItemStack item, BiConsumer<org.bukkit.entity.Player, org.bukkit.event.inventory.InventoryClickEvent> callback)
    Places a clickable button in the specified slot with an associated callback.
    setItem(int slot, org.bukkit.inventory.ItemStack item)
    Places an item in the specified slot of this menu.
    setPassthrough(boolean passthrough)
    Sets whether clicks in this menu pass through to the player's inventory.

    Methods inherited from class Object

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

    • plugin

      protected final Homestead plugin
    • inventory

      protected final org.bukkit.inventory.Inventory inventory
    • callbacks

      protected final Map<Integer, BiConsumer<org.bukkit.entity.Player, org.bukkit.event.inventory.InventoryClickEvent>> callbacks
    • passthrough

      protected boolean passthrough
  • Constructor Details

  • Method Details

    • builder

      public static Menu.Builder<?> builder(String menuKey, int size)
      Creates a new builder for a menu with the given title key and size.
      Parameters:
      menuKey - the key used to resolve the menu title from config
      size - the inventory size (must be a multiple of 9 between 9 and 54)
      Returns:
      a new Menu.Builder instance
    • builder

      public static Menu.Builder<?> builder(String menuKey, Placeholder placeholder, int size)
      Creates a new builder with a placeholder applied to the menu title.
      Parameters:
      menuKey - the key used to resolve the menu title from config
      placeholder - the placeholder to apply to the title
      size - the inventory size (must be a multiple of 9 between 9 and 54)
      Returns:
      a new Menu.Builder instance
    • builder

      public static Menu.Builder<?> builder(String menuKey, int size, boolean passthrough)
      Creates a new builder with passthrough mode enabled or disabled.
      Parameters:
      menuKey - the key used to resolve the menu title from config
      size - the inventory size (must be a multiple of 9 between 9 and 54)
      passthrough - whether clicks should pass through to the player inventory
      Returns:
      a new Menu.Builder instance
    • builder

      public static Menu.Builder<?> builder(String menuKey, Placeholder placeholder, int size, boolean passthrough)
      Creates a new builder with a placeholder and passthrough mode.
      Parameters:
      menuKey - the key used to resolve the menu title from config
      placeholder - the placeholder to apply to the title
      size - the inventory size (must be a multiple of 9 between 9 and 54)
      passthrough - whether clicks should pass through to the player inventory
      Returns:
      a new Menu.Builder instance
    • setPassthrough

      public Menu setPassthrough(boolean passthrough)
      Sets whether clicks in this menu pass through to the player's inventory.
      Parameters:
      passthrough - true to allow clicks to pass through
      Returns:
      this menu instance for chaining
    • setItem

      public Menu setItem(int slot, org.bukkit.inventory.ItemStack item)
      Places an item in the specified slot of this menu.
      Parameters:
      slot - the slot index to place the item in
      item - the item to place
      Returns:
      this menu instance for chaining
    • setButton

      public Menu setButton(int slot, org.bukkit.inventory.ItemStack item, BiConsumer<org.bukkit.entity.Player, org.bukkit.event.inventory.InventoryClickEvent> callback)
      Places a clickable button in the specified slot with an associated callback.
      Parameters:
      slot - the slot index for the button
      item - the item to display
      callback - the action to execute when the button is clicked, or null for no action
      Returns:
      this menu instance for chaining
    • fillEmptySlots

      public Menu fillEmptySlots(org.bukkit.inventory.ItemStack filler)
      Fills all empty slots in the inventory with the given filler item.
      Parameters:
      filler - the item to fill empty slots with
      Returns:
      this menu instance for chaining
    • fillEmptySlots

      public Menu fillEmptySlots()
      Fills all empty slots with the default empty slot item from MenuButtons.
      Returns:
      this menu instance for chaining
    • open

      public void open(org.bukkit.entity.Player player)
      Opens this menu for the specified player and registers the player with InventoryManager.
      Parameters:
      player - the player to open the menu for
    • destroy

      public void destroy()
      Unregisters this menu as a Bukkit event listener.
    • onInventoryClick

      public void onInventoryClick(org.bukkit.event.inventory.InventoryClickEvent event)
      Handles inventory click events, delegating registered button callbacks. Cancels the event unless passthrough is enabled.
      Parameters:
      event - the inventory click event
    • onInventoryClose

      public void onInventoryClose(org.bukkit.event.inventory.InventoryCloseEvent event)
      Handles inventory close events, unregistering the player and destroying this menu.
      Parameters:
      event - the inventory close event
    • isValidSlot

      protected boolean isValidSlot(int slot)
      Checks whether the given slot index is within the valid range for this inventory.
      Parameters:
      slot - the slot index to validate
      Returns:
      true if the slot is within bounds