Class BaseInventoryPage

java.lang.Object
mc.obliviate.inventory.Gui
com.ultikits.ultitools.abstracts.gui.BaseInventoryPage
All Implemented Interfaces:
org.bukkit.inventory.InventoryHolder
Direct Known Subclasses:
BaseConfirmationPage, BasePaginationPage

public abstract class BaseInventoryPage extends mc.obliviate.inventory.Gui
Base class for inventory GUI pages with common functionality. Uses Template Method pattern to allow customization while providing standard behaviors.
Since:
6.2.0
Version:
2.0.0
Author:
wisdomme
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Consumer<org.bukkit.event.inventory.InventoryCloseEvent>
    Custom close handler
    protected static final int
    Default slot for the last row background
    private boolean
    Whether to show the bottom toolbar

    Fields inherited from class mc.obliviate.inventory.Gui

    player
  • Constructor Summary

    Constructors
    Constructor
    Description
    BaseInventoryPage(@NotNull org.bukkit.entity.Player player, @NotNull String id, String title, int rows)
     
    BaseInventoryPage(@NotNull org.bukkit.entity.Player player, @NotNull String id, String title, org.bukkit.event.inventory.InventoryType inventoryType)
     
    BaseInventoryPage(@NotNull org.bukkit.entity.Player player, @NotNull String id, net.kyori.adventure.text.Component title, int rows)
     
    BaseInventoryPage(@NotNull org.bukkit.entity.Player player, @NotNull String id, net.kyori.adventure.text.Component title, org.bukkit.event.inventory.InventoryType inventoryType)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    addToBottomRow(int column, mc.obliviate.inventory.Icon icon)
    Adds an item to the last row at the specified column.
    protected void
    afterSetup(org.bukkit.event.inventory.InventoryOpenEvent event)
    Hook called after setup is complete.
    protected mc.obliviate.inventory.Icon
    createActionButton(Colors color, String name, Consumer<org.bukkit.event.inventory.InventoryClickEvent> onClick)
    Creates an action button with the specified color and name.
    protected mc.obliviate.inventory.Icon
    Creates the background icon for the toolbar.
    protected void
    fillArea(mc.obliviate.inventory.Icon icon, int startSlot, int endSlot)
    Fills a rectangular area with the specified icon.
    protected void
    fillBorder(mc.obliviate.inventory.Icon icon)
    Fills the border of the inventory with the specified icon.
    protected int
    Gets the slot number at the center of the last row.
    protected int[]
    Gets the content area slots (excluding the last row if toolbar is shown).
    protected int
    getSlotFromEnd(int fromEnd)
    Gets the slot number at the specified position from the end.
    onClose(Consumer<org.bukkit.event.inventory.InventoryCloseEvent> handler)
    Sets a custom close handler.
    void
    onClose(org.bukkit.event.inventory.InventoryCloseEvent event)
     
    final void
    onOpen(org.bukkit.event.inventory.InventoryOpenEvent event)
    Template method called when the GUI is opened.
    void
    Refreshes the GUI by re-opening it.
    setShowBottomToolbar(boolean show)
    Sets whether to show the bottom toolbar.
    protected void
    Sets up the standard bottom toolbar with gray background.
    protected abstract void
    setupContent(org.bukkit.event.inventory.InventoryOpenEvent event)
    Sets up the GUI content.

    Methods inherited from class mc.obliviate.inventory.Gui

    addItem, addItem, addItem, addItem, addItem, addItem, addItem, addItem, createInventory, createInventory, fillColumn, fillGui, fillGui, fillGui, fillGui, fillRow, getId, getInventory, getItems, getLastSlot, getPlugin, getSize, getTaskList, getTitle, isClosed, onClick, onDrag, open, runTaskLater, sendSizeUpdate, sendTitleUpdate, setClosed, setInventory, setSize, setTitle, stopAllTasks, stopTask, updateTask

    Methods inherited from class java.lang.Object

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

    • DEFAULT_BOTTOM_ROW

      protected static final int DEFAULT_BOTTOM_ROW
      Default slot for the last row background
      See Also:
    • showBottomToolbar

      private boolean showBottomToolbar
      Whether to show the bottom toolbar
    • closeHandler

      @Nullable private Consumer<org.bukkit.event.inventory.InventoryCloseEvent> closeHandler
      Custom close handler
  • Constructor Details

    • BaseInventoryPage

      public BaseInventoryPage(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull String id, String title, int rows)
    • BaseInventoryPage

      public BaseInventoryPage(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull String id, String title, org.bukkit.event.inventory.InventoryType inventoryType)
    • BaseInventoryPage

      public BaseInventoryPage(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull String id, net.kyori.adventure.text.Component title, int rows)
    • BaseInventoryPage

      public BaseInventoryPage(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull String id, net.kyori.adventure.text.Component title, org.bukkit.event.inventory.InventoryType inventoryType)
  • Method Details

    • onOpen

      public final void onOpen(org.bukkit.event.inventory.InventoryOpenEvent event)
      Template method called when the GUI is opened. Subclasses should override setupContent(InventoryOpenEvent) to add content.
      Overrides:
      onOpen in class mc.obliviate.inventory.Gui
    • setupContent

      protected abstract void setupContent(org.bukkit.event.inventory.InventoryOpenEvent event)
      Sets up the GUI content. Override this method to add custom content.
      Parameters:
      event - the inventory open event
    • afterSetup

      protected void afterSetup(org.bukkit.event.inventory.InventoryOpenEvent event)
      Hook called after setup is complete. Override for additional customization.
      Parameters:
      event - the inventory open event
    • setupBottomToolbar

      protected void setupBottomToolbar()
      Sets up the standard bottom toolbar with gray background.
    • createBackgroundIcon

      protected mc.obliviate.inventory.Icon createBackgroundIcon()
      Creates the background icon for the toolbar. Override to customize the background.
      Returns:
      the background icon
    • createActionButton

      protected mc.obliviate.inventory.Icon createActionButton(Colors color, String name, Consumer<org.bukkit.event.inventory.InventoryClickEvent> onClick)
      Creates an action button with the specified color and name.
      Parameters:
      color - the button color
      name - the button name
      onClick - the click handler
      Returns:
      the created icon
    • addToBottomRow

      protected void addToBottomRow(int column, mc.obliviate.inventory.Icon icon)
      Adds an item to the last row at the specified column. Column 0 is the leftmost slot.
      Parameters:
      column - the column (0-8 for 9-slot rows)
      icon - the icon to add
    • getBottomCenterSlot

      protected int getBottomCenterSlot()
      Gets the slot number at the center of the last row.
      Returns:
      the center slot of the last row
    • getSlotFromEnd

      protected int getSlotFromEnd(int fromEnd)
      Gets the slot number at the specified position from the end.
      Parameters:
      fromEnd - position from the end (1 = last slot)
      Returns:
      the slot number
    • setShowBottomToolbar

      public BaseInventoryPage setShowBottomToolbar(boolean show)
      Sets whether to show the bottom toolbar.
      Parameters:
      show - true to show, false to hide
      Returns:
      this page for method chaining
    • onClose

      public BaseInventoryPage onClose(Consumer<org.bukkit.event.inventory.InventoryCloseEvent> handler)
      Sets a custom close handler.
      Parameters:
      handler - the close handler
      Returns:
      this page for method chaining
    • onClose

      public void onClose(org.bukkit.event.inventory.InventoryCloseEvent event)
      Overrides:
      onClose in class mc.obliviate.inventory.Gui
    • refresh

      public void refresh()
      Refreshes the GUI by re-opening it.
    • fillArea

      protected void fillArea(mc.obliviate.inventory.Icon icon, int startSlot, int endSlot)
      Fills a rectangular area with the specified icon.
      Parameters:
      icon - the icon to fill with
      startSlot - the starting slot (top-left)
      endSlot - the ending slot (bottom-right)
    • fillBorder

      protected void fillBorder(mc.obliviate.inventory.Icon icon)
      Fills the border of the inventory with the specified icon.
      Parameters:
      icon - the icon to use for the border
    • getContentSlots

      protected int[] getContentSlots()
      Gets the content area slots (excluding the last row if toolbar is shown).
      Returns:
      array of content slot indices