Class HavenBagsAPI.GUI

java.lang.Object
valorless.havenbags.api.HavenBagsAPI.GUI
Enclosing class:
HavenBagsAPI

public static class HavenBagsAPI.GUI extends Object
GUI-related utilities for HavenBags.
  • Constructor Summary

    Constructors
    Constructor
    Description
    GUI()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    createBar(double progress, double total, int barLength)
    Creates a textual progress bar representation.
    static String
    createBar(double progress, double total, int barLength, String barColor, String fillColor, char barStyle, char fillStyle)
    Creates a customized textual progress bar representation.
    static org.bukkit.inventory.Inventory
    createPage(org.bukkit.entity.Player player, String title, int page, List<org.bukkit.inventory.ItemStack> items, int rows)
    Creates a paginated inventory GUI for displaying items.
    if the number of items exceeds the capacity of a single page, multiple pages will be created.
    static String
    getPageActionKey(org.bukkit.inventory.ItemStack button)
    Retrieves the action associated with a pagination button.
    static List<String>
    Gets the list of page number textures used for paginated GUIs.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GUI

      public GUI()
  • Method Details

    • createPage

      public static org.bukkit.inventory.Inventory createPage(org.bukkit.entity.Player player, String title, int page, List<org.bukkit.inventory.ItemStack> items, int rows)
      Creates a paginated inventory GUI for displaying items.
      if the number of items exceeds the capacity of a single page, multiple pages will be created.

      Each page will have the specified number of rows (up to 6), and navigation controls will be added to move between pages.
      The bottom row is reserved for navigation buttons.

      The buttons for navigation are placed in the bottom row of the inventory.
      Each button have their action stored in their PDC for handling clicks, as "havenbags:bag-action".

      PDC.SetString(button, "bag-action", action.toString());

      Possible actions are:
      - "prev-page": Go to the previous page.
      - "next-page": Go to the next page.
      - "return": Exit button.

      See getPageActionKey(ItemStack button) to retrieve the action from a button.

      Note: This method only creates a single page based on the provided page number.
      To handle multiple pages, you will need to call this method with different page numbers and manage the navigation logic in your plugin.

      Example usage:

       List<ItemStack> items = ...; // Your list of items to display
       int rows = 5; // Number of rows for the inventory
       int page = 0; // Page number to display
       Inventory inventory = HavenBagsAPI.GUI.createPage(player, "My Items", page, items, rows);
       player.openInventory(inventory);
       
      Parameters:
      player - The player for whom the inventory is created.
      title - The title of the inventory GUI.
      page - The page number to display (0-indexed).
      items - The list of ItemStacks to paginate.
      rows - The number of rows in the inventory (max 6).
      Returns:
      The created Inventory object representing the paginated GUI.
    • getPageActionKey

      public static String getPageActionKey(org.bukkit.inventory.ItemStack button)
      Retrieves the action associated with a pagination button.
      Parameters:
      button - The ItemStack representing the pagination button.
      Returns:
      The action string stored in the button's PDC, or null if not found.
    • getPageNumberTextures

      public static List<String> getPageNumberTextures()
      Gets the list of page number textures used for paginated GUIs.
      Returns:
      List of 32 (0-31) Base64-encoded texture strings for page numbers.
    • createBar

      public static String createBar(double progress, double total, int barLength)
      Creates a textual progress bar representation.
      Parameters:
      progress - The current progress value
      total - The total value for completion
      barLength - The length of the bar in characters
      Returns:
      A String representation of the progress bar
    • createBar

      public static String createBar(double progress, double total, int barLength, String barColor, String fillColor, char barStyle, char fillStyle)
      Creates a customized textual progress bar representation.
      Parameters:
      progress - The current progress value
      total - The total value for completion
      barLength - The length of the bar in characters
      barColor - The color code for the unfilled portion of the bar
      fillColor - The color code for the filled portion of the bar
      barStyle - The character to use for the unfilled portion of the bar
      fillStyle - The character to use for the filled portion of the bar
      Returns:
      A String representation of the customized progress bar