Gui
A class representing a GUI in the Colosseum plugin. This class is responsible for managing the inventory, handling clicks and drags, and refreshing the items in the GUI when necessary.
The GUI is built using a structure of AbstractItemProviders, which are responsible for providing the items to display in each slot of the inventory and handling clicks on those items. The GUI also supports virtual inventories.
To create a GUI, use the Builder class to define the structure of the GUI, set up item bindings and virtual inventory bindings, and then call buildAndOpen() to create and open the GUI for a player.
Parameters
The title of the GUI. This will be displayed at the top of the inventory when the GUI is open. If null, the default inventory title will be used.
The number of rows in the GUI. Each row contains 9 slots, so the total number of slots in the GUI will be size * 9. The maximum size is 6 rows
The player for whom the GUI will be opened. This is required to open the inventory and handle click events.
An array of AbstractItemProviders that defines the items to display in each slot
A map of virtual inventory IDs to their corresponding VirtualInventoryData, which contains the VirtualInventory instance and the list of providers associated with that virtual inventory. This is used to manage virtual inventories within the GUI and handle scrolling and refreshing of those inventories.
The instance of the ColosseumPlugin, used for registering listeners and scheduling tasks related to the GUI.
A boolean flag that determines whether the GUI can be closed by the player.
Types
A builder class for constructing a Gui instance. This class provides a fluent API for defining the structure of the GUI, setting up item bindings and virtual inventory bindings, and configuring other properties of the GUI before building and opening it for a player.
A data class representing the data associated with a virtual inventory within the GUI.
Properties
The inventory object representing the GUI. This is the actual Bukkit inventory that is opened for the player and contains the items displayed in the GUI. The inventory is created based on the specified size and title, and it is populated with items from the structure of AbstractItemProviders when the GUI is initialized. The inventory is also updated whenever providers are refreshed or when virtual inventories are scrolled.
Functions
Closes the GUI for the player by closing the inventory, unregistering the GUI listener, destroying any providers in the structure, and unregistering the GUI from any virtual inventories. This method is called when the player closes the inventory or when allowClose is true and the player attempts to close the GUI. It ensures that all resources associated with the GUI are properly cleaned up to prevent memory leaks or unintended behavior after the GUI is closed.
Handles scrolling for a virtual inventory. This method is called when a ScrollItemProvider is clicked, and it updates the slot of each provider in the virtual inventory by the specified scroll amount. It also refreshes the items in the GUI that are associated with the virtual inventory.
Handles click events in the inventory. When a slot is clicked, this method checks if the slot corresponds to a provider in the structure and calls the onClick() method of that provider. If the provider is a VirtualInventoryItemProvider, it creates a VirtualInventoryInteractEvent and passes it to the virtual inventory's handleClick() method. This allows for proper handling of clicks on both regular items and virtual inventory items within the GUI.
Opens the GUI for the player by registering the GUI listener and opening the inventory. This method is called when the GUI is initialized, and it ensures that the player can interact with the GUI and that click and drag events are properly handled by the listener.
Refreshes all items in the GUI by calling the getItem() method on each provider in the structure and updating the corresponding slot in the inventory.
Refreshes a specific index in the GUI by calling the getItem() method on the provider at that index in the structure and updating the corresponding slot in the inventory.
Refreshes all providers associated with a virtual inventory. This method is used to update the items displayed in the GUI for a virtual inventory, typically after scrolling or when the contents of the virtual inventory have changed. It calls the refresh() method on each provider associated with the specified virtual inventory, which will update the items in the GUI accordingly.
Refreshes a specific slot for a virtual inventory. This method is used to update a single slot in the GUI that is associated with a virtual inventory, typically after scrolling or when the contents of the virtual inventory have changed. It calls the refresh() method on the provider associated with the specified slot in the virtual inventory, which will update the item in the GUI for that slot accordingly.
Calculates the current scrolling window for a virtual inventory. This method returns a pair of integers representing the first and last slot indices of the virtual inventory that are currently being displayed in the GUI. This is used to determine which items from the virtual inventory should be shown based on the current scroll position.