Package tk.airshipcraft.commonlib.gui
Class UiDesigner
java.lang.Object
tk.airshipcraft.commonlib.gui.UiDesigner
A utility class designed for crafting and handling Graphical User Interfaces (GUIs) within Minecraft.
It provides a suite of methods to create and configure custom inventory GUIs, such as setting items in slots,
filling empty slots with placeholder items, managing inventory borders, and defining titles.
Extend this class to implement specific click actions and other interactive features for different GUIs.
- Since:
- 2023-04-09
- Version:
- 1.0.0
- Author:
- Locutusque, notzune
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract void
addClickAction
(org.bukkit.inventory.Inventory inventory, int slot) Abstract method to add a click action for a GUI.static void
callClickAction
(org.bukkit.inventory.Inventory inventory, int slot) Invokes the addClickAction method for all UiDesigner subclasses.void
clearInventory
(org.bukkit.inventory.Inventory inventory) Clears all items from the given inventory.static Ui
Creates a custom GUI (Graphical User Interface) inventory with a specific title and type.static org.bukkit.inventory.ItemStack
createItemStack
(org.bukkit.Material material, int amount, String name) Creates an item stack with specified material, amount, and custom name.void
fillSlots
(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack item) Fills all empty slots in the given inventory with the specified item stack.void
openInventoryForPlayer
(org.bukkit.entity.Player player, org.bukkit.inventory.Inventory inventory) Opens the specified inventory for the given player.void
setBorder
(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack item) Sets the border of the inventory with a specified item.void
setFiller
(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack item) Fills all empty slots that are not part of the border in the inventory with a specified item.void
setSlot
(org.bukkit.inventory.Inventory inventory, int slot, org.bukkit.inventory.ItemStack item) Set a specific slot in an inventory with a given item stack.void
Changes the title of the inventory.
-
Constructor Details
-
UiDesigner
public UiDesigner()Initializes a new SubclassFinder for UiDesigner subclasses. The SubclassFinder utility helps identify all subclasses of UiDesigner for click action processing.
-
-
Method Details
-
createGUI
Creates a custom GUI (Graphical User Interface) inventory with a specific title and type. This method simplifies the process of creating custom inventory interfaces.- Parameters:
title
- The title of the inventory GUI.type
- The type of the inventory (e.g., CHEST, HOPPER).rows
- The number of rows in the inventory (chest type).- Returns:
- A new Ui instance representing the custom GUI.
-
callClickAction
public static void callClickAction(org.bukkit.inventory.Inventory inventory, int slot) Invokes the addClickAction method for all UiDesigner subclasses. This allows the execution of click actions defined in UiDesigner subclasses when a player interacts with an inventory slot.- Parameters:
inventory
- The inventory where the interaction occurred.slot
- The slot number that was interacted with.
-
createItemStack
public static org.bukkit.inventory.ItemStack createItemStack(org.bukkit.Material material, int amount, String name) Creates an item stack with specified material, amount, and custom name. This method simplifies the process of creating customized items for UIs.- Parameters:
material
- The material of the item.amount
- The amount of the item.name
- The custom name of the item.- Returns:
- The created ItemStack.
-
clearInventory
public void clearInventory(org.bukkit.inventory.Inventory inventory) Clears all items from the given inventory.- Parameters:
inventory
- The inventory to clear.
-
openInventoryForPlayer
public void openInventoryForPlayer(org.bukkit.entity.Player player, org.bukkit.inventory.Inventory inventory) Opens the specified inventory for the given player. This method is useful for showing a custom UI to a player.- Parameters:
player
- The player to show the inventory to.inventory
- The inventory to be shown.
-
addClickAction
public abstract void addClickAction(org.bukkit.inventory.Inventory inventory, int slot) Abstract method to add a click action for a GUI. Subclasses of UiDesigner should override this method to provide specific behavior when a slot in the UI is clicked.- Parameters:
inventory
- The inventory in which the click occurred.slot
- The slot number that was clicked.
-
setSlot
public void setSlot(org.bukkit.inventory.Inventory inventory, int slot, org.bukkit.inventory.ItemStack item) Set a specific slot in an inventory with a given item stack.- Parameters:
inventory
- the inventory to modifyslot
- the slot to modifyitem
- the item stack to set in the slot
-
fillSlots
public void fillSlots(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack item) Fills all empty slots in the given inventory with the specified item stack.- Parameters:
inventory
- the inventory to fillitem
- the item stack to fill the inventory with
-
setBorder
public void setBorder(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack item) Sets the border of the inventory with a specified item. This method can be used to visually separate the content area from the edges in the GUI.- Parameters:
inventory
- The inventory to modify.item
- The ItemStack to use as a border.
-
setFiller
public void setFiller(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack item) Fills all empty slots that are not part of the border in the inventory with a specified item. This can be used to create a background effect or indicate unusable slots.- Parameters:
inventory
- The inventory to fill.item
- The ItemStack to use as filler for non-border slots.
-
setTitle
Changes the title of the inventory. This method will close the existing inventory for the player, if necessary, and open a new one with the new title. Note that changing the title is not possible without reopening the inventory.- Parameters:
inventory
- The inventory whose title is to be changed.title
- The new title for the inventory.
-