Class Menu
java.lang.Object
me.tayebyassine.homestead.gui.Menu
- All Implemented Interfaces:
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 -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<Integer, BiConsumer<org.bukkit.entity.Player, org.bukkit.event.inventory.InventoryClickEvent>> protected final org.bukkit.inventory.Inventoryprotected final Stringprotected booleanprotected final Homestead -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Menu.Builder<?> Creates a new builder for a menu with the given title key and size.static Menu.Builder<?> 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.voiddestroy()Unregisters this menu as a Bukkit event listener.Fills all empty slots with the default empty slot item fromMenuButtons.fillEmptySlots(org.bukkit.inventory.ItemStack filler) Fills all empty slots in the inventory with the given filler item.protected booleanisValidSlot(int slot) Checks whether the given slot index is within the valid range for this inventory.voidonInventoryClick(org.bukkit.event.inventory.InventoryClickEvent event) Handles inventory click events, delegating registered button callbacks.voidonInventoryClose(org.bukkit.event.inventory.InventoryCloseEvent event) Handles inventory close events, unregistering the player and destroying this menu.voidopen(org.bukkit.entity.Player player) Opens this menu for the specified player and registers the player withInventoryManager.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.
-
Field Details
-
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
-
Menu
-
-
Method Details
-
builder
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 configsize- the inventory size (must be a multiple of 9 between 9 and 54)- Returns:
- a new
Menu.Builderinstance
-
builder
Creates a new builder with a placeholder applied to the menu title.- Parameters:
menuKey- the key used to resolve the menu title from configplaceholder- the placeholder to apply to the titlesize- the inventory size (must be a multiple of 9 between 9 and 54)- Returns:
- a new
Menu.Builderinstance
-
builder
Creates a new builder with passthrough mode enabled or disabled.- Parameters:
menuKey- the key used to resolve the menu title from configsize- 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.Builderinstance
-
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 configplaceholder- the placeholder to apply to the titlesize- 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.Builderinstance
-
setPassthrough
Sets whether clicks in this menu pass through to the player's inventory.- Parameters:
passthrough-trueto allow clicks to pass through- Returns:
- this menu instance for chaining
-
setItem
Places an item in the specified slot of this menu.- Parameters:
slot- the slot index to place the item initem- 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 buttonitem- the item to displaycallback- the action to execute when the button is clicked, ornullfor no action- Returns:
- this menu instance for chaining
-
fillEmptySlots
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
Fills all empty slots with the default empty slot item fromMenuButtons.- 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 withInventoryManager.- 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:
trueif the slot is within bounds
-