Package eu.xap3y.xagui
Class GuiMenu
Object
GuiMenu
- All Implemented Interfaces:
GuiMenuInterface,InventoryHolder
Represents a paginated GUI menu.
Supports:
- Multiple pages with optional paginator controls
- Sticky slots rendered on every page
- Per-slot buttons with click listeners
- Per-inventory and self-inventory click policies (allow/blacklist)
- Open/close/click/page-switch callbacks
-
Field Summary
FieldsModifier and TypeFieldDescriptionCallback invoked on top-inventory clicks.Callback invoked on self-inventory clicks while viewing this GUI.Callback invoked on inventory close.Callback invoked on inventory open.Callback invoked after a page switch occurs.Tracks unlocked slots per page (page -> set of slot indices) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a default close button to page 0 (center of bottom row).voidaddCloseButton(int page, GuiButtonInterface button) Add a close button (GuiButtonInterface) to a specific page at the default close-slot.voidaddCloseButton(int page, ItemStack button) Add a close button (ItemStack) to a specific page at the default close-slot.voidAdd a default close button to all pages (center of bottom row).voidEnable paginator controls using the globally configured XaGui next/previous items.voidallowClickTypes(ClickType... types) Add allowed click types for the top (GUI) inventory.voidallowSelfInventoryClickTypes(ClickType... types) Allow only the specified self-inventory click types.voidblacklistClickTypes(ClickType... types) Add blacklisted click types for the top (GUI) inventory.voidcallback()Execute the configured callback action, if any.voidClear all buttons from the current page.voidclearAllSlots(int page) Clear all buttons from a specific page.voidclearSlot(int slot) Clear the button at a slot in the current page.voidclearSlot(int page, int slot) Clear the button at a slot in a specific page.voidclose()Close the GUI for the current viewer.voidclose(Player player) Close the GUI for a player on the main server thread.voidFill the border slots of all pages using the globally configured XaGui border filler.voidfillBorder(int page, ItemStack item) Fill the border slots of a specific page with an item.voidfillBorder(ItemStack item) Fill the border slots of the current page with an item.voidfillBorder(Material material) Fill the border slots of the current page with a material.voidfillSlots(int page, GuiButtonInterface item, int... slots) Fill the given slots on a specific page with a button.voidfillSlots(int page, ItemStack item, int... slots) Fill the given slots on a specific page with an ItemStack.voidfillSlots(GuiButtonInterface item, int... slots) Fill the given slots on the current page with a button instance.voidfillSlots(ItemStack item, int... slots) Fill the given slots on the current page with an ItemStack.voidFill the given slots on the current page with an ItemStack.voidFill the given slots on the current page with an ItemStack.voidFill the given slots on the current page with an ItemStack.ClickType[]Get the allowed top-inventory click types.ClickType[]Get the allowed self-inventory click types.ClickType[]Get the blacklisted top-inventory click types.intGet the one-based current page number.intGet the zero-based index of the current page.@NotNull InventoryGet the current page's Inventory.intGet the maximum pages currently allocated.getName()Get the colored title used for the inventory (translates & codes).SoundGet the sound played when opening the GUI.floatGet the volume of the sound played when opening the GUI.JavaPlugingetOwner()Get the owning plugin instance.intgetPages()Get the number of allocated pages.Get the uncolored, raw title value.booleanGet whether the player's own inventory can be interacted with while this menu is open.intgetSize()Get the inventory size in slots.getSlot(int slot) Get the button at a slot in the current page.getSlot(int page, int slot) Get the button at a slot in a specific page.booleanisButtonLocked(int slot) Check if a slot in the current page is locked.voidlockButton(int slot) Lock a slot on the current page, disallowing item pickup/move.voidlockButton(int page, int slot) Lock a slot on a specific page, disallowing item pickup/move.voidopen(int page, Player player) Open the GUI to a player at a specific page.voidopen(Player player) Open the GUI to a player at page 0.voidsetAllPageSlot(int slot, GuiButtonInterface button) Set the same button to the given slot across all pages.voidsetAllPageSlot(int slot, ItemStack item) Set the same ItemStack to the given slot across all pages.voidsetAllPageSlot(int slot, Material item) Set the same Material to the given slot across all pages.voidsetCallback(Runnable callback) Set a generic callback action that can be triggered viacallback().voidSet the (raw) name used as the inventory title.voidsetNextPageButton(ItemStack item) Set the item used for the "next page" control.voidsetOnClick(GuiClickInterface onClick) Set a handler invoked on clicks inside the top (GUI) inventory.voidsetOnClickOwn(GuiOwnClickInterface onClick) Set a handler invoked on clicks in the player's own inventory while this GUI is open.voidsetOnClose(GuiCloseInterface closeAction) Set a handler invoked when the inventory is closed.voidsetOnOpen(GuiOpenInterface openAction) Set a handler invoked when the inventory is opened.voidsetOnPageSwitch(GuiPageSwitchInterface onPageSwitch) Set a handler invoked after a page switch occurs.voidsetOpenSound(Sound sound, float volume) Set an optional sound to play when opening the GUI.voidsetPageSwitchSound(Sound sound) Set an optional sound to play when switching pages.voidsetPreviousPageButton(ItemStack item) Set the item used for the "previous page" control.voidsetSelfInventoryAccess(boolean value) Allow or disallow interaction with the player's own inventory while this menu is open.voidsetSlot(int page, int slot, GuiButtonInterface button) Set a button at a slot in a specific page.voidsetSlot(int page, int slot, ItemStack button) Set an ItemStack at a slot in a specific page.voidsetSlot(int page, int slot, Material button) Set a Material at a slot in a specific page.voidsetSlot(int slot, GuiButtonInterface button) Set a button at the given slot in the current page.voidsetSlot(int slot, ItemStack item) Set an ItemStack at the given slot in the current page.voidsetSlot(int slot, Material item) Set a Material at the given slot in the current page.voidsetSlotSafe(int page, int slot, GuiButtonInterface button) Internal helper to write slot state and backing Inventory safely.voidsetTotalPages(int pages) Reset total pages, clearing all current state and rebuilding internal mappings.voidstickSlot(int slot) Mark a slot as sticky so it is displayed on every page.voidswitchPage(int pageIndex, Player player) Switch the currently viewed page for a player.voidunlockButton(int slot) Unlock a slot on the current page, allowing item pickup/move.voidunlockButton(int page, int slot) Unlock a slot on a specific page, allowing item pickup/move.voidunStickSlot(int slot) Unmark a previously sticky slot.voidupdateSlot(int page, int slot, ItemStack item) Update the ItemStack in a slot on a specific page.voidupdateSlot(int page, int slot, Material item) Update the Material in a slot on a specific page.voidupdateSlot(int slot, ItemStack item) Update the ItemStack in a slot on the current page.voidupdateSlot(int slot, Material item) Update the Material in a slot on the current page.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface GuiMenuInterface
setOpenSound
-
Field Details
-
unlockedSlots
-
onCloseAction
Callback invoked on inventory close. -
onOpenAction
Callback invoked on inventory open. -
onClickAction
Callback invoked on top-inventory clicks. -
onClickActionOwn
Callback invoked on self-inventory clicks while viewing this GUI. -
onPageSwitchAction
Callback invoked after a page switch occurs.
-
-
Constructor Details
-
GuiMenu
Create a new GUI menu.- Parameters:
plugin- the owning plugintitle- the menu title (supports color codes with &)rowsToSet- number of rows (1-6 typical)pages- initial number of pages to allocate
-
-
Method Details
-
getInventory
@NotNull public @NotNull Inventory getInventory()Get the current page's Inventory.- Specified by:
getInventoryin interfaceInventoryHolder- Returns:
- the currently active page inventory
-
close
public void close()Close the GUI for the current viewer.- Specified by:
closein interfaceGuiMenuInterface
-
setOnOpen
Set a handler invoked when the inventory is opened.- Specified by:
setOnOpenin interfaceGuiMenuInterface- Parameters:
openAction- open handler
-
setOnClose
Set a handler invoked when the inventory is closed.- Specified by:
setOnClosein interfaceGuiMenuInterface- Parameters:
closeAction- close handler
-
setOnClick
Set a handler invoked on clicks inside the top (GUI) inventory.- Specified by:
setOnClickin interfaceGuiMenuInterface- Parameters:
onClick- click handler
-
setOnClickOwn
Set a handler invoked on clicks in the player's own inventory while this GUI is open.- Specified by:
setOnClickOwnin interfaceGuiMenuInterface- Parameters:
onClick- own-inventory click handler
-
setOnPageSwitch
Set a handler invoked after a page switch occurs.- Specified by:
setOnPageSwitchin interfaceGuiMenuInterface- Parameters:
onPageSwitch- page switch handler
-
setName
Set the (raw) name used as the inventory title.- Specified by:
setNamein interfaceGuiMenuInterface- Parameters:
newName- the new raw title
-
getName
Get the colored title used for the inventory (translates & codes).- Specified by:
getNamein interfaceGuiMenuInterface- Returns:
- colored title
-
getRawName
Get the uncolored, raw title value.- Specified by:
getRawNamein interfaceGuiMenuInterface- Returns:
- raw title
-
getSize
public int getSize()Get the inventory size in slots.- Specified by:
getSizein interfaceGuiMenuInterface- Returns:
- rows * 9
-
getPages
public int getPages()Get the number of allocated pages.- Specified by:
getPagesin interfaceGuiMenuInterface- Returns:
- total pages mapping currently created
-
getCurrentPageIndex
public int getCurrentPageIndex()Get the zero-based index of the current page.- Specified by:
getCurrentPageIndexin interfaceGuiMenuInterface- Returns:
- current page index
-
getCurrentPage
public int getCurrentPage()Get the one-based current page number.- Specified by:
getCurrentPagein interfaceGuiMenuInterface- Returns:
- current page number
-
setSlot
Set a button at the given slot in the current page.- Specified by:
setSlotin interfaceGuiMenuInterface- Parameters:
slot- slot indexbutton- button instance
-
setAllPageSlot
Set the same button to the given slot across all pages.- Specified by:
setAllPageSlotin interfaceGuiMenuInterface- Parameters:
slot- slot indexbutton- button instance to reuse
-
setAllPageSlot
public void setAllPageSlot(int slot, ItemStack item) Set the same ItemStack to the given slot across all pages.- Specified by:
setAllPageSlotin interfaceGuiMenuInterface- Parameters:
slot- slot indexitem- itemstack to place
-
setAllPageSlot
public void setAllPageSlot(int slot, Material item) Set the same Material to the given slot across all pages.- Specified by:
setAllPageSlotin interfaceGuiMenuInterface- Parameters:
slot- slot indexitem- material to place (amount 1)
-
setSlot
public void setSlot(int slot, ItemStack item) Set an ItemStack at the given slot in the current page.- Specified by:
setSlotin interfaceGuiMenuInterface- Parameters:
slot- slot indexitem- itemstack to place
-
setSlot
public void setSlot(int slot, Material item) Set a Material at the given slot in the current page.- Specified by:
setSlotin interfaceGuiMenuInterface- Parameters:
slot- slot indexitem- material to place (amount 1)
-
setSlot
Set a button at a slot in a specific page.- Specified by:
setSlotin interfaceGuiMenuInterface- Parameters:
page- page index (0-based)slot- slot indexbutton- button to place
-
setSlotSafe
Internal helper to write slot state and backing Inventory safely.- Parameters:
page- page index (0-based)slot- slot indexbutton- button to place
-
setSlot
public void setSlot(int page, int slot, ItemStack button) Set an ItemStack at a slot in a specific page.- Specified by:
setSlotin interfaceGuiMenuInterface- Parameters:
page- page index (0-based)slot- slot indexbutton- itemstack to place
-
setSlot
public void setSlot(int page, int slot, Material button) Set a Material at a slot in a specific page.- Specified by:
setSlotin interfaceGuiMenuInterface- Parameters:
page- page index (0-based)slot- slot indexbutton- material to place (amount 1)
-
updateSlot
public void updateSlot(int slot, ItemStack item) Update the ItemStack in a slot on the current page.- Specified by:
updateSlotin interfaceGuiMenuInterface- Parameters:
slot- slot indexitem- new itemstack
-
updateSlot
public void updateSlot(int slot, Material item) Update the Material in a slot on the current page.- Specified by:
updateSlotin interfaceGuiMenuInterface- Parameters:
slot- slot indexitem- new material (amount 1)
-
updateSlot
public void updateSlot(int page, int slot, ItemStack item) Update the ItemStack in a slot on a specific page.- Specified by:
updateSlotin interfaceGuiMenuInterface- Parameters:
page- page index (0-based)slot- slot indexitem- new itemstack
-
updateSlot
public void updateSlot(int page, int slot, Material item) Update the Material in a slot on a specific page.- Specified by:
updateSlotin interfaceGuiMenuInterface- Parameters:
page- page index (0-based)slot- slot indexitem- new material (amount 1)
-
getSlot
Get the button at a slot in the current page.- Specified by:
getSlotin interfaceGuiMenuInterface- Parameters:
slot- slot index- Returns:
- button or null
-
getSlot
Get the button at a slot in a specific page.- Specified by:
getSlotin interfaceGuiMenuInterface- Parameters:
page- page index (0-based)slot- slot index- Returns:
- button or null
-
clearSlot
public void clearSlot(int slot) Clear the button at a slot in the current page.- Specified by:
clearSlotin interfaceGuiMenuInterface- Parameters:
slot- slot index
-
clearSlot
public void clearSlot(int page, int slot) Clear the button at a slot in a specific page.- Specified by:
clearSlotin interfaceGuiMenuInterface- Parameters:
page- page index (0-based)slot- slot index
-
clearAllSlots
public void clearAllSlots()Clear all buttons from the current page.- Specified by:
clearAllSlotsin interfaceGuiMenuInterface
-
clearAllSlots
public void clearAllSlots(int page) Clear all buttons from a specific page.- Specified by:
clearAllSlotsin interfaceGuiMenuInterface- Parameters:
page- page index (0-based)
-
getOwner
public JavaPlugin getOwner()Get the owning plugin instance.- Specified by:
getOwnerin interfaceGuiMenuInterface- Returns:
- owner plugin
-
unlockButton
public void unlockButton(int slot) Unlock a slot on the current page, allowing item pickup/move.- Specified by:
unlockButtonin interfaceGuiMenuInterface- Parameters:
slot- slot index
-
unlockButton
public void unlockButton(int page, int slot) Unlock a slot on a specific page, allowing item pickup/move.- Specified by:
unlockButtonin interfaceGuiMenuInterface- Parameters:
page- page index (0-based)slot- slot index
-
lockButton
public void lockButton(int slot) Lock a slot on the current page, disallowing item pickup/move.- Specified by:
lockButtonin interfaceGuiMenuInterface- Parameters:
slot- slot index
-
lockButton
public void lockButton(int page, int slot) Lock a slot on a specific page, disallowing item pickup/move.- Specified by:
lockButtonin interfaceGuiMenuInterface- Parameters:
page- page index (0-based)slot- slot index
-
isButtonLocked
public boolean isButtonLocked(int slot) Check if a slot in the current page is locked.- Specified by:
isButtonLockedin interfaceGuiMenuInterface- Parameters:
slot- slot index- Returns:
- true if locked; false if unlocked
-
open
public void open(Player player) Open the GUI to a player at page 0.- Specified by:
openin interfaceGuiMenuInterface- Parameters:
player- target player
-
open
public void open(int page, Player player) Open the GUI to a player at a specific page.- Specified by:
openin interfaceGuiMenuInterface- Parameters:
page- page index (0-based)player- target player
-
switchPage
public void switchPage(int pageIndex, Player player) Switch the currently viewed page for a player. Adds paginator controls if configured and plays an optional page switch sound.- Specified by:
switchPagein interfaceGuiMenuInterface- Parameters:
pageIndex- target page index (0-based)player- the player viewing the GUI- Throws:
PageOutOfBoundException- if the index is negative or exceeds max pages
-
getMaxPages
public int getMaxPages()Get the maximum pages currently allocated.- Specified by:
getMaxPagesin interfaceGuiMenuInterface- Returns:
- total page count
-
stickSlot
public void stickSlot(int slot) Mark a slot as sticky so it is displayed on every page.- Specified by:
stickSlotin interfaceGuiMenuInterface- Parameters:
slot- slot index
-
unStickSlot
public void unStickSlot(int slot) Unmark a previously sticky slot.- Specified by:
unStickSlotin interfaceGuiMenuInterface- Parameters:
slot- slot index
-
close
public void close(Player player) Close the GUI for a player on the main server thread.- Specified by:
closein interfaceGuiMenuInterface- Parameters:
player- the player to close for
-
fillSlots
public void fillSlots(ItemStack item, int... slots) Fill the given slots on the current page with an ItemStack.- Specified by:
fillSlotsin interfaceGuiMenuInterface- Parameters:
item- itemstack to placeslots- varargs of slot indices
-
fillSlots
Fill the given slots on the current page with an ItemStack.- Specified by:
fillSlotsin interfaceGuiMenuInterface- Parameters:
item- itemstack to placeslots- array of slot indices
-
fillSlots
Fill the given slots on the current page with an ItemStack.- Specified by:
fillSlotsin interfaceGuiMenuInterface- Parameters:
item- itemstack to placeslots- set of slot indices
-
fillSlots
Fill the given slots on the current page with an ItemStack.- Specified by:
fillSlotsin interfaceGuiMenuInterface- Parameters:
item- itemstack to placeslots- list of slot indices
-
fillSlots
Fill the given slots on the current page with a button instance.- Specified by:
fillSlotsin interfaceGuiMenuInterface- Parameters:
item- button instanceslots- varargs of slot indices
-
fillSlots
public void fillSlots(int page, ItemStack item, int... slots) Fill the given slots on a specific page with an ItemStack.- Specified by:
fillSlotsin interfaceGuiMenuInterface- Parameters:
page- page index (0-based)item- itemstack to placeslots- varargs of slot indices
-
fillSlots
Fill the given slots on a specific page with a button.- Specified by:
fillSlotsin interfaceGuiMenuInterface- Parameters:
page- page index (0-based)item- button instanceslots- varargs of slot indices
-
addCloseButton
public void addCloseButton()Add a default close button to page 0 (center of bottom row).- Specified by:
addCloseButtonin interfaceGuiMenuInterface
-
addCloseButtonAllPages
public void addCloseButtonAllPages()Add a default close button to all pages (center of bottom row).- Specified by:
addCloseButtonAllPagesin interfaceGuiMenuInterface
-
addCloseButton
public void addCloseButton(int page, ItemStack button) Add a close button (ItemStack) to a specific page at the default close-slot.- Specified by:
addCloseButtonin interfaceGuiMenuInterface- Parameters:
page- page index (0-based)button- itemstack to use
-
addCloseButton
Add a close button (GuiButtonInterface) to a specific page at the default close-slot.- Specified by:
addCloseButtonin interfaceGuiMenuInterface- Parameters:
page- page index (0-based)button- button instance to use
-
addPaginator
public void addPaginator()Enable paginator controls using the globally configured XaGui next/previous items.- Specified by:
addPaginatorin interfaceGuiMenuInterface
-
setNextPageButton
public void setNextPageButton(ItemStack item) Set the item used for the "next page" control.- Specified by:
setNextPageButtonin interfaceGuiMenuInterface- Parameters:
item- itemstack for next page
-
setPreviousPageButton
public void setPreviousPageButton(ItemStack item) Set the item used for the "previous page" control.- Specified by:
setPreviousPageButtonin interfaceGuiMenuInterface- Parameters:
item- itemstack for previous page
-
setPageSwitchSound
public void setPageSwitchSound(Sound sound) Set an optional sound to play when switching pages.- Specified by:
setPageSwitchSoundin interfaceGuiMenuInterface- Parameters:
sound- page switch sound (nullable to disable)
-
setOpenSound
public void setOpenSound(Sound sound, float volume) Set an optional sound to play when opening the GUI.- Specified by:
setOpenSoundin interfaceGuiMenuInterface- Parameters:
sound- open sound (nullable to disable)volume- sound volume
-
getOpenSound
public Sound getOpenSound()Get the sound played when opening the GUI.- Specified by:
getOpenSoundin interfaceGuiMenuInterface- Returns:
- open sound
-
getOpenSoundVolume
public float getOpenSoundVolume()Get the volume of the sound played when opening the GUI.- Specified by:
getOpenSoundVolumein interfaceGuiMenuInterface- Returns:
- open sound volume
-
fillBorder
public void fillBorder()Fill the border slots of all pages using the globally configured XaGui border filler.- Specified by:
fillBorderin interfaceGuiMenuInterface
-
fillBorder
public void fillBorder(int page, ItemStack item) Fill the border slots of a specific page with an item.- Specified by:
fillBorderin interfaceGuiMenuInterface- Parameters:
page- page index (0-based)item- itemstack to place in border
-
fillBorder
public void fillBorder(ItemStack item) Fill the border slots of the current page with an item.- Specified by:
fillBorderin interfaceGuiMenuInterface- Parameters:
item- itemstack to place in border
-
fillBorder
public void fillBorder(Material material) Fill the border slots of the current page with a material.- Specified by:
fillBorderin interfaceGuiMenuInterface- Parameters:
material- material to place (amount 1)
-
setSelfInventoryAccess
public void setSelfInventoryAccess(boolean value) Allow or disallow interaction with the player's own inventory while this menu is open.- Specified by:
setSelfInventoryAccessin interfaceGuiMenuInterface- Parameters:
value- true to allow; false to deny
-
getSelfInventoryAccess
public boolean getSelfInventoryAccess()Get whether the player's own inventory can be interacted with while this menu is open.- Specified by:
getSelfInventoryAccessin interfaceGuiMenuInterface- Returns:
- true if allowed; false otherwise
-
allowSelfInventoryClickTypes
public void allowSelfInventoryClickTypes(ClickType... types) Allow only the specified self-inventory click types. If any types are set here, only those will be allowed for the player's own inventory.- Specified by:
allowSelfInventoryClickTypesin interfaceGuiMenuInterface- Parameters:
types- allowed self-inventory click types
-
getAllowedSelfInventoryClickTypes
public ClickType[] getAllowedSelfInventoryClickTypes()Get the allowed self-inventory click types.- Specified by:
getAllowedSelfInventoryClickTypesin interfaceGuiMenuInterface- Returns:
- array of allowed click types (empty means not restricted here)
-
allowClickTypes
public void allowClickTypes(ClickType... types) Add allowed click types for the top (GUI) inventory. If any are configured, a click not present here will be denied.- Specified by:
allowClickTypesin interfaceGuiMenuInterface- Parameters:
types- allowed top-inventory click types
-
blacklistClickTypes
public void blacklistClickTypes(ClickType... types) Add blacklisted click types for the top (GUI) inventory. If configured, any click present here will be denied.- Specified by:
blacklistClickTypesin interfaceGuiMenuInterface- Parameters:
types- blacklisted top-inventory click types
-
getAllowedClickTypes
public ClickType[] getAllowedClickTypes()Get the allowed top-inventory click types.- Specified by:
getAllowedClickTypesin interfaceGuiMenuInterface- Returns:
- array of allowed click types (empty means not restricted here)
-
getBlacklistedClickTypes
public ClickType[] getBlacklistedClickTypes()Get the blacklisted top-inventory click types.- Specified by:
getBlacklistedClickTypesin interfaceGuiMenuInterface- Returns:
- array of blacklisted click types
-
callback
public void callback()Execute the configured callback action, if any.- Specified by:
callbackin interfaceGuiMenuInterface
-
setCallback
Set a generic callback action that can be triggered viacallback().- Specified by:
setCallbackin interfaceGuiMenuInterface- Parameters:
callback- runnable to execute
-
setTotalPages
public void setTotalPages(int pages) Reset total pages, clearing all current state and rebuilding internal mappings.- Specified by:
setTotalPagesin interfaceGuiMenuInterface- Parameters:
pages- new total page count
-