Buttons

Creating a Button

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

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

Button Styling

You can use any of the following methods to style aButton:

Any updates to a Button will be immediately reflected in the Gui without having to explicitly update the Gui.

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

Click Handling

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

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
            }
        });

Last updated