Class Ui
java.lang.Object
tk.airshipcraft.commonlib.gui.objects.Ui
Represents a custom User Interface (UI) in Minecraft, facilitating the creation and management of custom inventory interfaces.
This class allows for the design and interaction of inventory-based GUIs such as chests or hoppers, with custom layouts and functionalities.
It supports adding items as buttons and managing these interfaces within the Minecraft environment.
- Since:
- 2023-11-20
- Version:
- 1.0.0
- Author:
- Locutusque, notzune
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddButton(org.bukkit.inventory.ItemStack item, int slot) Adds an item as a button to the UI at the specified slot.org.bukkit.inventory.InventoryObtains the Inventory object representing this UI.Gets the unique identifier of this UI instance.Retrieves the name of the UI's inventory.org.bukkit.inventory.InventoryHoldergetOwner()Retrieves the InventoryHolder associated with this UI.intgetRows()Retrieves the number of rows in the UI's inventory.org.bukkit.event.inventory.InventoryTypegetType()Gets the type of the UI's inventory.static booleanisUi(org.bukkit.inventory.Inventory inventory) Checks if a given inventory is a custom UI created by this class.
-
Constructor Details
-
Ui
public Ui(String inventoryName, org.bukkit.inventory.InventoryHolder owner, org.bukkit.event.inventory.InventoryType type, int rows) Constructs a new Ui instance with specified parameters. This constructor sets up a custom inventory interface, which can be a chest, hopper, etc., based on the provided type and rows.- Parameters:
inventoryName- The name of the inventory, displayed at the top of the UI.owner- The InventoryHolder associated with this UI, can be null.type- The type of inventory (e.g., CHEST, HOPPER) to create.rows- The number of rows in the inventory if it's a chest type.
-
-
Method Details
-
isUi
public static boolean isUi(org.bukkit.inventory.Inventory inventory) Checks if a given inventory is a custom UI created by this class. This static method can be used to verify if an inventory is part of the custom UI system.- Parameters:
inventory- The Inventory to check.- Returns:
- True if the inventory is a custom UI created by this class, false otherwise.
-
addButton
public void addButton(org.bukkit.inventory.ItemStack item, int slot) Adds an item as a button to the UI at the specified slot. This method places an ItemStack in the inventory at a given slot, which can represent a button or an interactive element.- Parameters:
item- The ItemStack to be added as a button.slot- The inventory slot where the item will be placed.
-
getInventoryName
Retrieves the name of the UI's inventory.- Returns:
- The name of the inventory.
-
getInventoryId
Gets the unique identifier of this UI instance. This UUID can be used to distinguish and track individual UIs.- Returns:
- The UUID of the inventory.
-
getOwner
public org.bukkit.inventory.InventoryHolder getOwner()Retrieves the InventoryHolder associated with this UI. The InventoryHolder represents the entity or object that holds this UI.- Returns:
- The InventoryHolder of this UI, which may be null.
-
getInventory
public org.bukkit.inventory.Inventory getInventory()Obtains the Inventory object representing this UI. This inventory is the actual container in which items and buttons are placed.- Returns:
- The Inventory instance representing this UI.
-
getType
public org.bukkit.event.inventory.InventoryType getType()Gets the type of the UI's inventory. The type determines the layout and behavior of the inventory (e.g., chest, hopper).- Returns:
- The InventoryType of this UI.
-
getRows
public int getRows()Retrieves the number of rows in the UI's inventory. This is relevant for types like chests that have a variable number of rows.- Returns:
- The number of rows in the inventory.
-