Button

data class Button @JvmOverloads constructor(val slot: Int, val material: Material, val name: Component, val data: Map<NamespacedKey, DataWrapper<out Any, out Any>> = emptyMap(), var onClick: ClickEvent? = null, val skipGUIListenerCall: Boolean = true)

Represents a button in an inventory GUI. This class is used to define the properties and behavior of a button, including its material, display name, custom data, and click action.

Since

1.1.0

Author

RiriFa

Constructors

Link copied to clipboard
constructor(slot: Int, material: Material, name: Component, data: Map<NamespacedKey, DataWrapper<out Any, out Any>> = emptyMap(), onClick: ClickEvent? = null, skipGUIListenerCall: Boolean = true)

Properties

Link copied to clipboard
val data: Map<NamespacedKey, DataWrapper<out Any, out Any>>

A map of persistent data stored in the button's item. The keys are namespaced keys, and the values are wrapped in a data wrapper.

Link copied to clipboard
val material: Material

The material that represents this button visually.

Link copied to clipboard
val name: Component

The display name of the button, shown in the inventory.

Link copied to clipboard

An optional lambda function executed when the button is clicked. The function takes the Player who clicked the button as a parameter.

Link copied to clipboard

A flag indicating whether to skip further GUI listener calls after this button is clicked.

Link copied to clipboard
val slot: Int

The inventory slot where this button will be placed.

Functions

Link copied to clipboard
fun Button.addData(vararg entries: Pair<NamespacedKey, DataWrapper<*, *>>): Button

Adds multiple persistent data entries to the button.

Link copied to clipboard
fun Button.appendClick(callback: (Player) -> Unit): Button

Adds a click handler to the button without overwriting the existing one. The new click handler is called after the existing click handler when the button is clicked.

Link copied to clipboard
fun Button.setClick(block: (Player) -> Unit): Button
fun <G> Button.setClick(gui: G, block: (Player, G) -> Unit): Button
fun <S : Enum<S>> Button.setClick(gui: DynamicGUI<S>, block: (Player, DynamicGUI<S>) -> Unit): Button
fun <S : Enum<S>> Button.setClick(gui: PaginatedDynamicGUI<S>, block: (Player, PaginatedDynamicGUI<S>) -> Unit): Button
Link copied to clipboard
inline fun <G : InventoryGUI> Button.setClickTyped(crossinline block: (Player, G) -> Unit): Button
fun <G : InventoryGUI> Button.setClickTyped(guiClass: Class<G>, block: (Player, G) -> Unit): Button
Link copied to clipboard
fun Button.setData(key: NamespacedKey, wrapper: DataWrapper<*, *>): Button

Sets or replaces a single persistent data entry in the button.

Link copied to clipboard
fun toItemStack(): ItemStack

Converts the button's material, display name, and custom data into an ItemStack.