Package dev.crafty.core.gui
Class Menu
java.lang.Object
dev.crafty.core.gui.Menu
- All Implemented Interfaces:
org.bukkit.event.Listener
- Since:
- 1.0.0
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
Consumer
<org.bukkit.event.inventory.InventoryClickEvent> int
getCurrentPage
(String sourceId) Get the current page number for a mapped item source.Supplier
<org.bukkit.inventory.ItemStack> getMetadataFromItem
(String key, org.bukkit.inventory.ItemStack item) getPaginationState
(String sourceId, int itemsPerPage, int totalItems) Get or create a pagination state for a mapped item source.protected <T> T
getPrefetchedData
(String key, Class<T> type) Retrieve prefetched data by key.int
getTotalPages
(String sourceId) Get the total number of pages for a mapped item source.org.bukkit.entity.Player
boolean
goNextPage
(String sourceId) Navigate to the next page for a mapped item source.boolean
goPreviousPage
(String sourceId) Navigate to the previous page for a mapped item source.boolean
hasNextPage
(String sourceId) Check if there is a next page available for a mapped item source.boolean
hasPreviousPage
(String sourceId) Check if there is a previous page available for a mapped item source.void
onInventoryClick
(org.bukkit.event.inventory.InventoryClickEvent event) void
onInventoryClose
(org.bukkit.event.inventory.InventoryCloseEvent event) void
open()
Opens the menu after ensuring all data is prefetched.void
open
(boolean stacked) Opens the menu after ensuring all data is prefetched.protected CompletableFuture
<Void> Override this method to asynchronously fetch data needed for the menu.void
Refresh the mapped items by recreating the inventory.protected void
registerAction
(String id, Consumer<org.bukkit.event.inventory.InventoryClickEvent> action) protected void
registerItemSupplier
(String id, Supplier<org.bukkit.inventory.ItemStack> supplier) protected <T> void
registerMappedItemConfig
(String id, Function<T, Map<String, String>> metadata, Function<T, Map<String, String>> replacements, List<T> items) void
registerPlaceholder
(String key, Function<org.bukkit.entity.Player, String> replacer) Register a local placeholder for this menu.boolean
Jump to a specific page for a mapped item source.protected abstract void
setup()
protected <T> void
storePrefetchedData
(String key, T data) Store prefetched data with a key for later use in setup().
-
Field Details
-
MENU_NAMESPACE
- See Also:
-
id
-
player
protected final org.bukkit.entity.Player player -
plugin
protected final org.bukkit.plugin.Plugin plugin
-
-
Constructor Details
-
Menu
-
-
Method Details
-
registerPlaceholder
Register a local placeholder for this menu. The function receives the player and returns the replacement string. -
setup
protected abstract void setup() -
storePrefetchedData
Store prefetched data with a key for later use in setup(). This method should be called within prefetchData().- Type Parameters:
T
- The type of data being stored- Parameters:
key
- The key to store the data underdata
- The data to store
-
getPrefetchedData
Retrieve prefetched data by key. This method should be called within setup().- Type Parameters:
T
- The type of data to retrieve- Parameters:
key
- The key the data was stored undertype
- The class of the data type- Returns:
- The data, or null if not found
- Throws:
IllegalStateException
- if called before prefetchData() completes
-
prefetchData
Override this method to asynchronously fetch data needed for the menu. This method will be called before setup() and the menu will only open once this completes. Use storePrefetchedData() to store data that will be needed in setup().- Returns:
- A CompletableFuture that completes when all data is loaded
-
open
public void open()Opens the menu after ensuring all data is prefetched. If prefetchData() hasn't been called yet, it will be called before opening. -
open
public void open(boolean stacked) Opens the menu after ensuring all data is prefetched. If prefetchData() hasn't been called yet, it will be called before opening.- Parameters:
stacked
- Whether this menu is being stacked on top of another menu
-
onInventoryClick
public void onInventoryClick(org.bukkit.event.inventory.InventoryClickEvent event) -
onInventoryClose
public void onInventoryClose(org.bukkit.event.inventory.InventoryCloseEvent event) -
registerAction
-
getAction
-
registerItemSupplier
-
getItemSupplier
-
addItem
-
addItems
-
getViewer
public org.bukkit.entity.Player getViewer() -
getPaginationState
Get or create a pagination state for a mapped item source.- Parameters:
sourceId
- The source ID for the mapped itemsitemsPerPage
- Number of items per pagetotalItems
- Total number of items- Returns:
- The pagination state
-
goNextPage
Navigate to the next page for a mapped item source.- Parameters:
sourceId
- The source ID for the mapped items- Returns:
- true if navigation was successful
-
goPreviousPage
Navigate to the previous page for a mapped item source.- Parameters:
sourceId
- The source ID for the mapped items- Returns:
- true if navigation was successful
-
setPage
Jump to a specific page for a mapped item source.- Parameters:
sourceId
- The source ID for the mapped itemspageNum
- The page number to navigate to (0-based)- Returns:
- true if navigation was successful
-
getCurrentPage
Get the current page number for a mapped item source.- Parameters:
sourceId
- The source ID for the mapped items- Returns:
- Current page number (0-based), or -1 if source not found
-
getTotalPages
Get the total number of pages for a mapped item source.- Parameters:
sourceId
- The source ID for the mapped items- Returns:
- Total number of pages, or 0 if source not found
-
hasNextPage
Check if there is a next page available for a mapped item source.- Parameters:
sourceId
- The source ID for the mapped items- Returns:
- true if next page exists
-
hasPreviousPage
Check if there is a previous page available for a mapped item source.- Parameters:
sourceId
- The source ID for the mapped items- Returns:
- true if previous page exists
-
refreshMappedItems
public void refreshMappedItems()Refresh the mapped items by recreating the inventory. This is called automatically when pagination changes occur. -
registerMappedItemConfig
-
getMappedItemConfig
-
getMetadataFromItem
-