Package dev.oumaimaa.kawaiiapi.menu
Class Menu
java.lang.Object
dev.oumaimaa.kawaiiapi.menu.Menu
- All Implemented Interfaces:
org.bukkit.inventory.InventoryHolder
- Direct Known Subclasses:
PaginatedMenu
Abstract base class for creating custom inventory menus using modern Paper API.
Provides a comprehensive framework for menu creation with built-in utilities
for item creation and inventory management.
Features:
- Adventure Component support for all text
- Automatic filler glass placement
- Menu history and navigation
- Customizable click handling
- Close event handling
- Version:
- 1.0
- Author:
- KawaiiDevelopment
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.bukkit.inventory.ItemStackprotected org.bukkit.inventory.Inventoryprotected final org.bukkit.entity.Playerprotected final PlayerMenuUtility -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMenu(@NotNull PlayerMenuUtility playerMenuUtility) Constructs a new Menu instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidback()Navigates back to the previous menu in the history stack.abstract booleanDetermines whether all inventory clicks should be cancelled by default.@NotNull org.bukkit.inventory.Inventoryabstract @NotNull StringGets the name/title of this menu to be displayed in the inventory.protected @NotNull org.bukkit.entity.PlayerGets the player who owns this menu instance.protected @NotNull PlayerMenuUtilityGets the PlayerMenuUtility associated with this menu.abstract intgetSlots()Gets the number of slots for this menu inventory.abstract voidhandleMenu(@NotNull org.bukkit.event.inventory.InventoryClickEvent e) Handles click events within this menu.voidCalled when a player closes this menu.protected booleanisOpen()Checks if the menu is currently open.protected @NotNull org.bukkit.inventory.ItemStackmakeItem(@NotNull org.bukkit.Material material, int amount, @NotNull String displayName, @NotNull String... lore) Creates an ItemStack with a specific amount.protected @NotNull org.bukkit.inventory.ItemStackmakeItem(@NotNull org.bukkit.Material material, @NotNull String displayName, @NotNull String... lore) Creates an ItemStack with display name and lore using modern Components.voidopen()Opens this menu for the player.protected voidplaySound(@NotNull org.bukkit.Sound sound, float volume, float pitch) Plays a sound to the player viewing this menu.protected voidreload()Closes and reopens this menu, effectively performing a full refresh.protected voidReloads the current menu by clearing and repopulating all items.protected voidsendMessage(@NotNull String message) Sends a message to the player viewing this menu.voidFills all empty slots in the inventory with the default filler glass.voidsetFillerGlass(@NotNull org.bukkit.inventory.ItemStack itemStack) Fills all empty slots with a custom filler item.abstract voidSets up all items in the menu inventory.
-
Field Details
-
playerMenuUtility
-
player
protected final org.bukkit.entity.Player player -
inventory
protected org.bukkit.inventory.Inventory inventory -
FILLER_GLASS
protected org.bukkit.inventory.ItemStack FILLER_GLASS
-
-
Constructor Details
-
Method Details
-
getMenuName
Gets the name/title of this menu to be displayed in the inventory. Supports legacy color codes (&) and hex colors (invalid input: '&#'RRGGBB).- Returns:
- The menu name
-
getSlots
public abstract int getSlots()Gets the number of slots for this menu inventory. Must be a multiple of 9, between 9 and 54.- Returns:
- The slot count
-
cancelAllClicks
public abstract boolean cancelAllClicks()Determines whether all inventory clicks should be cancelled by default. Return true for non-interactive menus, false for menus where players can take items.- Returns:
- true to cancel all clicks, false to allow item interaction
-
handleMenu
public abstract void handleMenu(@NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent e) throws MenuManagerNotSetupException, MenuManagerException Handles click events within this menu. Override this method to implement custom click behavior.- Parameters:
e- The InventoryClickEvent to handle- Throws:
MenuManagerNotSetupException- If the MenuManager is not initializedMenuManagerException- If an error occurs during menu handling
-
setMenuItems
public abstract void setMenuItems()Sets up all items in the menu inventory. Called when the menu is opened or reloaded. Override this method to populate your menu with items. -
open
public void open()Opens this menu for the player. Creates the inventory, populates items, and displays it to the player. -
back
Navigates back to the previous menu in the history stack.- Throws:
MenuManagerException- If menu navigation failsMenuManagerNotSetupException- If the MenuManager is not initialized
-
reloadItems
protected void reloadItems()Reloads the current menu by clearing and repopulating all items. Maintains the menu open while refreshing content. -
reload
Closes and reopens this menu, effectively performing a full refresh.- Throws:
MenuManagerException- If menu reload failsMenuManagerNotSetupException- If the MenuManager is not initialized
-
getInventory
@NotNull public @NotNull org.bukkit.inventory.Inventory getInventory()- Specified by:
getInventoryin interfaceorg.bukkit.inventory.InventoryHolder
-
setFillerGlass
public void setFillerGlass()Fills all empty slots in the inventory with the default filler glass. -
setFillerGlass
public void setFillerGlass(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack) Fills all empty slots with a custom filler item.- Parameters:
itemStack- The item to use as filler
-
makeItem
@NotNull protected @NotNull org.bukkit.inventory.ItemStack makeItem(@NotNull @NotNull org.bukkit.Material material, @NotNull @NotNull String displayName, @NotNull @NotNull String... lore) Creates an ItemStack with display name and lore using modern Components. Automatically translates color codes using ColorTranslator.- Parameters:
material- The material typedisplayName- The display name (supports & and invalid input: '&#'RRGGBB)lore- The lore lines (supports & and invalid input: '&#'RRGGBB)- Returns:
- The constructed ItemStack
-
makeItem
@NotNull protected @NotNull org.bukkit.inventory.ItemStack makeItem(@NotNull @NotNull org.bukkit.Material material, int amount, @NotNull @NotNull String displayName, @NotNull @NotNull String... lore) Creates an ItemStack with a specific amount.- Parameters:
material- The material typeamount- The stack size (1-64, automatically clamped)displayName- The display namelore- The lore lines- Returns:
- The constructed ItemStack
-
handleMenuClose
public void handleMenuClose()Called when a player closes this menu. Override this method to handle menu closing events (cleanup, saving data, etc.). Called before the inventory is actually closed. -
getPlayer
@NotNull protected @NotNull org.bukkit.entity.Player getPlayer()Gets the player who owns this menu instance.- Returns:
- The player instance
-
getPlayerMenuUtility
Gets the PlayerMenuUtility associated with this menu.- Returns:
- The PlayerMenuUtility instance
-
isOpen
protected boolean isOpen()Checks if the menu is currently open.- Returns:
- true if the player has this menu open
-
sendMessage
Sends a message to the player viewing this menu.- Parameters:
message- The message to send (supports color codes)
-
playSound
protected void playSound(@NotNull @NotNull org.bukkit.Sound sound, float volume, float pitch) Plays a sound to the player viewing this menu.- Parameters:
sound- The sound to playvolume- The volume (0.0-1.0)pitch- The pitch (0.5-2.0)
-