Class GUI
java.lang.Object
me.block2block.hubparkour.api.gui.GUI
Represents a graphical user interface (GUI) that can be displayed to a player in a Minecraft environment.
This abstract class handles the creation, management, and interaction with GUI items and inventory slots.
This GUI framework relies on an implementing listener that handles inventory clicks, closes and opens.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanDetermines whether events, such as clicks, within the GUI should be cancelled.intgetSize()Calculates the total size of the GUI's inventory based on the number of rows.booleanisOpen()Checks if the GUI is currently open.abstract voidAbstract method invoked when a click action occurs within the GUI at a specified row and column.voidopen()Opens the GUI for the player associated with this instance, initializing its content based on the provided configuration.voidSets aGUIItemat the specified row and column in the GUI.voidupdateItem(int row, int column, GUIItem item) Updates the item in the specified row and column of the GUI.
-
Field Details
-
player
-
-
Constructor Details
-
GUI
Constructs a new GUI instance with the specified parameters. The GUI is designed to represent a graphical interface for players, comprised of rows, columns, and optional event cancellation behavior. Rows must be within the range of 0 to 5 inclusive.- Parameters:
player- The player who will interact with the GUI.name- The display name of the GUI.rows- The number of rows in the GUI, which must be between 0 and 5 inclusive.cancelEvent- Determines whether the click events in the GUI will be cancelled.- Throws:
InvalidRowException- If the number of rows is outside the valid range (0 to 5).
-
-
Method Details
-
setItem
Sets aGUIItemat the specified row and column in the GUI. The row and column indices must be within their respective valid ranges. This will not update the GUI if it is already open.- Parameters:
row- The row index where the item will be placed. Must be between 0 and 5 inclusive.column- The column index where the item will be placed. Must be between 0 and 8 inclusive.item- TheGUIItemto be placed at the specified position. Can be null to clear the slot.- Throws:
InvalidRowException- If the row index is not within the range 0-5.InvalidColumnException- If the column index is not within the range 0-8.
-
updateItem
Updates the item in the specified row and column of the GUI. If the provided item is null, the slot in the inventory is cleared. Otherwise, the item is set in the specified location within the inventory. This will update the GUI if its open.- Parameters:
row- The row index to update. Must be between 0 and 5 inclusive.column- The column index to update. Must be between 0 and 8 inclusive.item- TheGUIItemto set at the specified position. If null, the corresponding slot in the inventory will be cleared.
-
open
public void open()Opens the GUI for the player associated with this instance, initializing its content based on the provided configuration. If the player already has a GUI open, it will close the existing one before opening the new GUI.The method creates an inventory with dimensions determined by the rows and columns defined in this instance. Each slot of the inventory is populated with items from the internal inventory data structure, retaining the layout specified during the GUI's construction or modification.
Once the inventory is prepared, it is displayed to the player and registered for tracking in the
HubParkourAPI. If the player's open inventory is null after attempting to open, the method exits early. -
getSize
public int getSize()Calculates the total size of the GUI's inventory based on the number of rows. The size is determined as the product of the rows and 9, where 9 represents the number of columns per row in the GUI.- Returns:
- The total number of slots in the GUI, calculated as rows * 9.
-
onClick
Abstract method invoked when a click action occurs within the GUI at a specified row and column. This method is intended to handle specific user interactions with items present in the GUI. This is automatically called by the plugin.- Parameters:
row- The row index of the clicked slot. Must be between 0 and 5 inclusive.column- The column index of the clicked slot. Must be between 0 and 8 inclusive.item- The ItemStack present in the clicked slot. Can be null if the slot is empty.clickType- The type of click action performed (e.g., left-click, right-click, shift-click).
-
cancelEvent
public boolean cancelEvent()Determines whether events, such as clicks, within the GUI should be cancelled.- Returns:
- true if GUI events should be cancelled; false otherwise.
-
border
-
isOpen
public boolean isOpen()Checks if the GUI is currently open.- Returns:
- true if the GUI is marked as open.
-