GuiButton
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 theGuiButton
object.onClick(onClick: (KGui.Builder, Player) -> Unit)
: Sets the left-click event handler for the button and returns theGuiButton
object.onRightClick(onRightClick: (KGui.Builder, Player) -> Unit)
: Sets the right-click event handler for the button and returns theGuiButton
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:
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.