Class HavenBagsAPI.GUI
- Enclosing class:
- HavenBagsAPI
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcreateBar(double progress, double total, int barLength) Creates a textual progress bar representation.static StringcreateBar(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.InventorycreatePage(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 StringgetPageActionKey(org.bukkit.inventory.ItemStack button) Retrieves the action associated with a pagination button.Gets the list of page number textures used for paginated GUIs.
-
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
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
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
Creates a textual progress bar representation.- Parameters:
progress- The current progress valuetotal- The total value for completionbarLength- 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 valuetotal- The total value for completionbarLength- The length of the bar in charactersbarColor- The color code for the unfilled portion of the barfillColor- The color code for the filled portion of the barbarStyle- The character to use for the unfilled portion of the barfillStyle- The character to use for the filled portion of the bar- Returns:
- A String representation of the customized progress bar
-