# Buttons

## Creating a Button

A `Button` can be created using either the `Button.of(ItemType)` factory method.

{% tabs %}
{% tab title="Java" %}

```java
Button button = Button.of(ItemType.DIAMOND);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val button: Button = Button.of(ItemType.DIAMOND)
```

{% endtab %}
{% endtabs %}

## Button Styling

You can use any of the following methods to style a`Button`:

{% hint style="info" %}
Any updates to a `Button` will be immediately reflected in the `Gui` without having to explicitly update the `Gui`.
{% endhint %}

{% tabs %}
{% tab title="Java" %}

```java
Button button = Button.of(ItemType.DIAMOND)
        .name(Component.text("A Button"))
        .lore(Component.text("Line 1"), Component.text("Line 2"))
        .glow(true)
        .amount(3);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val button = Button.of(ItemType.DIAMOND)
        .name(Component.text("My Button"))
        .lore(Component.text("Line 1"), Component.text("Line 2"))
        .amount(3)
```

{% endtab %}
{% endtabs %}

## Click Handling

`Button` clicks can be handled using the `onClick(Consumer<Click>)` method:

{% tabs %}
{% tab title="Java" %}

```java
Button button = Button.of(ItemType.DIAMOND)
        .onClick(click -> {
            Audience clicker = click.clicker(); // who clicked
            ClickType type = click.type(); // click type (left, right, etc)
            
            if (clicker instanceof Player player) {
                // check if the clicker is a player
            }
        });
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val button = Button.of(ItemType.DIAMOND)
        .onClick { click -> 
            val clicker = click.clicker() // who clicked
            val type = click.type() // click type (left, right, etc)
            
            if (clicker is Player) {
                // check if the clicker is a player
            }
        }
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vision.sparky983.me/guides/buttons.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
