DynamicGUI

class DynamicGUI<S : Enum<S>>(enumClass: Class<S>, player: Player) : InventoryGUI

A generic dynamic GUI framework for creating inventories with an adaptive state-based design.

Since

1.1.0

The DynamicGUI class extends InventoryGUI to provide enhanced functionality for creating GUIs that dynamically change based on specific predefined states. Each state is defined by an enum parameter, allowing the GUI to map buttons and functionality specific to each state.

Features:

  • Manages state transitions and updates the GUI accordingly.

  • Allows the creation of mappings between states and button configurations.

  • Supports dynamic updates of inventory content based on the current state.

Parameters

S

The type of the state enumeration that defines the various states the GUI can have.

player

The player for whom this GUI is being created.

See also

Constructors

Link copied to clipboard
constructor(enumKClass: KClass<S>, player: Player)
constructor(player: Player)
constructor(enumClass: Class<S>, player: Player)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Represents the list of buttons to be displayed in this inventory GUI. Each button corresponds to a slot and can define its own material, name, custom data, and click behavior.

Link copied to clipboard

Functions

Link copied to clipboard

Adds a single item to the existing item list.

Link copied to clipboard
open override fun build(): InventoryGUI

Abstract method for building the inventory GUI. This method should be implemented by subclasses to define the layout and items of the GUI.

Link copied to clipboard
fun close()

Closes the inventory for the player.

Link copied to clipboard
open override fun getAllButtons(): List<Button>
Link copied to clipboard
fun getBackgroundMaterial(): Material?

Gets the background material set for the inventory GUI.

Link copied to clipboard
open override fun getInventory(): Inventory

Returns the inventory associated with this GUI.

Link copied to clipboard

Gets the current listener associated with this GUI.

Link copied to clipboard
fun getSize(): Int?

Gets the size of the inventory GUI.

Link copied to clipboard
fun getTitle(): Component?

Gets the title of this GUI.

Link copied to clipboard
fun onClose(block: (DynamicGUI<S>) -> Unit): DynamicGUI<S>

Sets a handler to be called when this GUI is closed.

Link copied to clipboard
fun open()

Opens the inventory for the player.

Link copied to clipboard
fun setBackground(background: Material): InventoryGUI

Sets the background material for the inventory GUI.

Link copied to clipboard

Sets the button mappings for the DynamicGUI. Each state is associated with a list of buttons that define the appearance and functionality of the GUI in that state.

Link copied to clipboard

Sets multiple items at once for the GUI. This replaces the existing item list.

Link copied to clipboard

Sets the listener for handling GUI events.

Link copied to clipboard
fun setShouldCallGlobalListener(shouldCallGlobalListener: Boolean): InventoryGUI

Sets whether the global listener should be called on inventory events.

Link copied to clipboard

Sets the size of the inventory GUI.

Link copied to clipboard
fun setState(initialState: S): DynamicGUI<S>

Sets the current state of the DynamicGUI to the specified initial state.

Link copied to clipboard
fun setTitle(title: Component): InventoryGUI

Sets the title of the inventory GUI.

Link copied to clipboard

Indicates whether the global listener should be called on inventory events.

Link copied to clipboard
fun switchState(newState: S)

Updates the state of the DynamicGUI to a new state and refreshes the buttons to match the new state. If the new state is the same as the current state, no action is taken.

Link copied to clipboard

Updates the inventory GUI to reflect the buttons associated with the current state. This method clears the existing inventory, applies a background if specified, and sets the buttons mapped to the current state into the inventory.