Class Menu

java.lang.Object
dev.crafty.core.gui.Menu
All Implemented Interfaces:
org.bukkit.event.Listener

public abstract class Menu extends Object implements org.bukkit.event.Listener
Since:
1.0.0
  • Field Details

    • id

      protected final String id
    • player

      protected final org.bukkit.entity.Player player
    • plugin

      protected final org.bukkit.plugin.Plugin plugin
  • Constructor Details

  • Method Details

    • registerPlaceholder

      public void registerPlaceholder(String key, Function<org.bukkit.entity.Player,String> replacer)
      Register a local placeholder for this menu. The function receives the player and returns the replacement string.
    • setup

      protected abstract void setup()
    • storePrefetchedData

      protected <T> void storePrefetchedData(String key, T data)
      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 under
      data - The data to store
    • getPrefetchedData

      protected <T> T getPrefetchedData(String key, Class<T> type)
      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 under
      type - The class of the data type
      Returns:
      The data, or null if not found
      Throws:
      IllegalStateException - if called before prefetchData() completes
    • prefetchData

      protected CompletableFuture<Void> 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

      protected void registerAction(String id, Consumer<org.bukkit.event.inventory.InventoryClickEvent> action)
    • getAction

      public Consumer<org.bukkit.event.inventory.InventoryClickEvent> getAction(String id)
    • registerItemSupplier

      protected void registerItemSupplier(String id, Supplier<org.bukkit.inventory.ItemStack> supplier)
    • getItemSupplier

      public Supplier<org.bukkit.inventory.ItemStack> getItemSupplier(String id)
    • addItem

      public void addItem(GuiItem item)
    • addItems

      public void addItems(GuiItem... items)
    • getViewer

      public org.bukkit.entity.Player getViewer()
    • getPaginationState

      public PaginationState getPaginationState(String sourceId, int itemsPerPage, int totalItems)
      Get or create a pagination state for a mapped item source.
      Parameters:
      sourceId - The source ID for the mapped items
      itemsPerPage - Number of items per page
      totalItems - Total number of items
      Returns:
      The pagination state
    • goNextPage

      public boolean goNextPage(String sourceId)
      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

      public boolean goPreviousPage(String sourceId)
      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

      public boolean setPage(String sourceId, int pageNum)
      Jump to a specific page for a mapped item source.
      Parameters:
      sourceId - The source ID for the mapped items
      pageNum - The page number to navigate to (0-based)
      Returns:
      true if navigation was successful
    • getCurrentPage

      public int getCurrentPage(String sourceId)
      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

      public int getTotalPages(String sourceId)
      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

      public boolean hasNextPage(String sourceId)
      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

      public boolean hasPreviousPage(String sourceId)
      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

      protected <T> void registerMappedItemConfig(String id, Function<T,Map<String,String>> metadata, Function<T,Map<String,String>> replacements, List<T> items)
    • getMappedItemConfig

      public Optional<Menu.MappedItemConfig<?>> getMappedItemConfig(String id)
    • getMetadataFromItem

      public String getMetadataFromItem(String key, org.bukkit.inventory.ItemStack item)