Package dev.crafty.core.gui
Class Menu
java.lang.Object
dev.crafty.core.gui.Menu
- All Implemented Interfaces:
org.bukkit.event.Listener
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidConsumer<org.bukkit.event.inventory.InventoryClickEvent> intgetCurrentPage(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> TgetPrefetchedData(String key, Class<T> type) Retrieve prefetched data by key.intgetTotalPages(String sourceId) Get the total number of pages for a mapped item source.org.bukkit.entity.PlayervoidgoNextPage(String sourceId) Navigate to the next page for a mapped item source.voidgoPreviousPage(String sourceId) Navigate to the previous page for a mapped item source.booleanhasNextPage(String sourceId) Check if there is a next page available for a mapped item source.booleanhasPreviousPage(String sourceId) Check if there is a previous page available for a mapped item source.voidonInventoryClick(org.bukkit.event.inventory.InventoryClickEvent event) voidonInventoryClose(org.bukkit.event.inventory.InventoryCloseEvent event) voidopen()Opens the menu after ensuring all data is prefetched.voidopen(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.voidRefresh the mapped items by recreating the inventory.voidRefreshes the entire menu, including reloading configuration.protected voidregisterAction(String id, Consumer<org.bukkit.event.inventory.InventoryClickEvent> action) protected voidregisterItemSupplier(String id, Supplier<org.bukkit.inventory.ItemStack> supplier) protected <T> voidregisterMappedItemConfig(String id, Function<T, Map<String, String>> metadata, Function<T, Map<String, String>> replacements, List<T> items) voidregisterPlaceholder(String key, Function<org.bukkit.entity.Player, String> replacer) Register a local placeholder for this menu.voidJump to a specific page for a mapped item source.protected abstract voidsetup()protected <T> voidstorePrefetchedData(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
-
goPreviousPage
Navigate to the previous page for a mapped item source.- Parameters:
sourceId- The source ID for the mapped items
-
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)
-
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. -
refreshMenu
public void refreshMenu()Refreshes the entire menu, including reloading configuration. This should be called when the menu configuration has been reloaded. -
registerMappedItemConfig
-
getMappedItemConfig
-
getMetadataFromItem
-