-
Notifications
You must be signed in to change notification settings - Fork 9
Creating and displaying your first GUI
SamJakob edited this page Dec 16, 2017
·
4 revisions
Description: This guide will show you how to create your first GUI using the Paginated GUI API.
Time: 2-3 minutes
Difficulty: 2/5 (Easy)
- Go to the place, in your code, that you want to use a Paginated GUI...
// Instantiate the GUI
PaginatedGUI menu = new PaginatedGUI("My Paginated GUI");
- Next, create a button:
// Instantiate the GUIButton
// This takes an ItemStack as an argument, however I have created an
// ItemBuilder class to create custom ItemStacks very easily.
GUIButton button = new GUIButton(
ItemBuilder.start(Material.BOOK).name("&eView the rules")
.lore(Arrays.asList("&eMy first button!")).build()
);
- Now, set the button's listener.
// Yep - that's right. Lambda support!
button.setListener(event -> {
event.setCancelled(true);
event.getWhoClicked().sendMessage("1. Don't cheat!");
});
- Finally, add the button to the GUI
menu.addButton(button);
To show your brand new GUI to a player, simply use:
// Open the inventory on the player's screen
player.openInventory(menu.getInventory());