Buttons
Creating a Button
A Button can be created using either the Button.of(ItemType) factory method.
Button button = Button.of(ItemType.DIAMOND);val 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);val button = Button.of(ItemType.DIAMOND)
.name(Component.text("My Button"))
.lore(Component.text("Line 1"), Component.text("Line 2"))
.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
}
});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
}
}Last updated
Was this helpful?