GuiButton

class GuiButton(var item: ItemStack, val onClick: (InventoryClickEvent) -> Unit, val scope: EventScope<InventoryClickEvent> = EventScope(), val metadata: MutableMap<String, Any> = mutableMapOf(), val delay: Long = 0, val debounce: Long = 0, val throttle: Long = 0, val animationFrames: List<ItemStack> = emptyList(), val animationInterval: Long = 20)

Represents a clickable button within a GUI, which can have various actions, animations, and metadata.

This class provides the ability to configure a button with an item, assign click actions, manage cooldowns, set up animations, and store additional metadata.

Parameters

item

The item that represents the button in the inventory.

onClick

The action that will be triggered when the button is clicked.

scope

The event scope that controls the conditions under which the button's action is triggered.

metadata

The metadata associated with the button.

delay

The delay (in ticks) before the button's action is triggered.

debounce

The debounce time (in ticks) to prevent multiple clicks in quick succession.

throttle

The throttle time (in milliseconds) to limit how frequently the button's action can be triggered.

animationFrames

A list of item frames for animating the button.

animationInterval

The interval (in ticks) between animation frames.

Constructors

Link copied to clipboard
constructor(item: ItemStack, onClick: (InventoryClickEvent) -> Unit, scope: EventScope<InventoryClickEvent> = EventScope(), metadata: MutableMap<String, Any> = mutableMapOf(), delay: Long = 0, debounce: Long = 0, throttle: Long = 0, animationFrames: List<ItemStack> = emptyList(), animationInterval: Long = 20)

Properties

Link copied to clipboard
val animationFrames: List<ItemStack>
Link copied to clipboard
Link copied to clipboard
val debounce: Long = 0
Link copied to clipboard
val delay: Long = 0
Link copied to clipboard
var item: ItemStack
Link copied to clipboard
Link copied to clipboard
val onClick: (InventoryClickEvent) -> Unit
Link copied to clipboard
val scope: EventScope<InventoryClickEvent>
Link copied to clipboard
val throttle: Long = 0

Functions

Link copied to clipboard
fun bind(inventory: Inventory, slot: Int)

Binds the button to a specific inventory and slot.

Link copied to clipboard
fun <T> getMeta(key: String): T?

Retrieves the metadata value associated with the specified key.

Link copied to clipboard

Checks whether the button has metadata associated with the specified key.

Link copied to clipboard

Retrieves all the metadata keys associated with this button.

Link copied to clipboard

Pauses the animation, stopping the frame updates.

Link copied to clipboard

Removes the metadata associated with the specified key.

Link copied to clipboard

Resumes the animation if it was paused.

Link copied to clipboard
fun <T> setMeta(key: String, value: T): GuiButton

Sets the metadata value for a specific key.

Link copied to clipboard

Starts the animation for this button, cycling through the provided animation frames.

Link copied to clipboard

Stops the animation for this button, resetting the frame index.

Link copied to clipboard
fun trigger(event: InventoryClickEvent)

Triggers the button's action when it is clicked, considering any debounce, delay, and throttle settings.