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.

带有通用功能的背包 GUI 页面基类。 使用模板方法模式允许自定义,同时提供标准行为。

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.

      GUI 打开时调用的模板方法。 子类应重写 setupContent(InventoryOpenEvent) 来添加内容。

      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.

      设置 GUI 内容。重写此方法以添加自定义内容。

      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.

      在最后一行的指定列添加项目。 列 0 是最左边的槽位。

      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.

      通过重新打开 GUI 来刷新它。

    • 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