GUI
The main implementation of the lib.

Creating a GUI

To create a GUI all you need to do is:
1
// Main way to create a GUI
2
Gui gui = Gui.gui()
3
.title(Component.text("GUI Title!"))
4
.rows(6)
5
.create();
6
7
// Typed GUI
8
Gui gui = Gui.gui()
9
.title(Component.text("GUI Title!"))
10
.type(GuiType.DISPENSER)
11
.create();
Copied!
If rows are used instead of the type, it'll use GuiType.CHEST.
Current supported GUI types:
  • CHEST - Default - 0 to 53 slots
  • WORKBENCH - 0 to 9 slots
  • HOPPER - 0 to 4 slots
  • DISPENSER - 0 to 8 slots
  • BREWING - 0 to 4 slots

Creating a GUI item

Each item added to the GUI need to be a GuiItem.
1
// Alternatively you can use the ItemBuilder
2
GuiItem guiItem = ItemBuilder.from(Material.STONE).asGuiItem();
3
GuiItem guiItem = ItemBuilder.from(Material.STONE).asGuiItem(event -> {
4
// Handle your click action here
5
});
Copied!
Each GUI item needs an item stack, you may want to add a click action or not. The action for an item is simply the InventoryClickEvent so handle it like you would be doing your own listener.

Adding the item to the GUI

Now that we have our GuiItem, we can easily add it to the GUI.
1
// Using a slot number from 0 to 53
2
gui.setItem(slot, guiItem);
3
4
// Using rows and columns
5
gui.setItem(row, col, guiItem);
6
7
// Using add item to add to next free slot
8
gui.addItem(guiItem);
Copied!
You have the option to set it the way you want, for example the slot 0 is the row 1, col 1. Attention as if you specify a slot that exceeds the GUI limit it'll throw a GuiException.

Opening the GUI

To open the GUI to the player you just need to call the method open.
1
gui.open(player);
Copied!
Last modified 22d ago