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
:
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
Was this helpful?