NextDevv's Docs Help

GuiButton

class GuiButton { private var itemStack: ItemStack? = null private var onClick: ((KGui.Builder, Player) -> Unit)? = null private var onRightClick: ((KGui.Builder, Player) -> Unit)? = null fun setItemStack(itemStack: ItemStack): GuiButton { this.itemStack = itemStack return this } fun onClick(onClick: (KGui.Builder, Player) -> Unit): GuiButton { this.onClick = onClick return this } fun onRightClick(onRightClick: (KGui.Builder, Player) -> Unit): GuiButton { this.onRightClick = onRightClick return this } fun getItemStack(): ItemStack? { return itemStack } fun getOnClick(): ((KGui.Builder, Player) -> Unit)? { return onClick } fun getOnRightClick(): ((KGui.Builder, Player) -> Unit)? { return onRightClick } }

Description & Properties

The GuiButton class is used to create interactive buttons within a GUI. It has the following properties and methods:

  • itemStack: The item stack to display as the button's icon.

  • onClick: A lambda function that is called when the button is left-clicked.

  • onRightClick: A lambda function that is called when the button is right-clicked.

  • setItemStack(itemStack: ItemStack): Sets the item stack for the button and returns the GuiButton object.

  • onClick(onClick: (KGui.Builder, Player) -> Unit): Sets the left-click event handler for the button and returns the GuiButton object.

  • onRightClick(onRightClick: (KGui.Builder, Player) -> Unit): Sets the right-click event handler for the button and returns the GuiButton object.

  • getItemStack(): ItemStack?: Returns the item stack of the button.

  • getOnClick(): ((KGui.Builder, Player) -> Unit)?: Returns the left-click event handler of the button.

  • getOnRightClick(): ((KGui.Builder, Player) -> Unit)?: Returns the right-click event handler of the button.

Example

You can create a GuiButton object, set its properties, and attach event handlers to it to create interactive buttons within your GUIs. The itemStack property defines the appearance of the button, while the onClick and onRightClick properties define the actions to be performed when the button is clicked.

Here is an example of how to create a GuiButton object in Kotlin:

val button = GuiButton() button.setItemStack(ItemStack(Material.DIAMOND_SWORD)) button.onClick { builder, player -> player.sendMessage("You clicked the button!") } button.onRightClick { builder, player -> player.sendMessage("You right-clicked the button!") }

In this example, we create a GuiButton object with a diamond sword icon and attach left-click and right-click event handlers to it. When the button is clicked, a message is sent to the player indicating the type of click that was performed.

Summary

You can use GuiButton objects to create custom buttons with unique functionality in your GUIs, allowing players to interact with your plugin in a more engaging and intuitive way.

Last modified: 03 July 2024