-
Notifications
You must be signed in to change notification settings - Fork 2
Example: Create a GUI
worldOneo edited this page Jan 1, 2022
·
1 revision
When the player joins only the following code is needed to give the players a button in the hotbar.
HotbarGui hotbar = Gui.hotbar();
hotbar.setDefaultClickHandler(c -> c.cancel()); // Cancel all hotbar events
hotbar.addModifier(Modifiers.fillEmpty(new ItemStack(Material.STAINED_GLASS_PANE))); // Fill all empty slots with stained glass
IWidget playerHider = new Button(this::openSelector) // Run on click
.setMaterial(Material.BLAZE_ROD) // Blaze rod as button
.setTitle("§ePlayerHider") // Title
.setSlot(4); // In the middle of the hotbar
hotbar.addWidget(playerHider); // Add the widget to the hotbar
hotbar.open(player); // Change the hotbar for the player
For the UI we will use an brewing stand. This is our openSelector function:
public void openSelector(ClickContext e) {
Let us first create the inventory of type BREWING:
InventoryGui gui = Gui.inventory() // Create an inventory UI
.setGUITitle("§ePlayerHider")
.setInventoryType(InventoryType.BREWING); // Set the type
Add the options for player hider:
// Create three buttons for the player options
IWidget hidePlayers = new Button(this::hideAllPlayers)
.setMaterial(Material.GLASS)
.setTitle("§cHide all players").setSlot(0);
IWidget showPlayers = new Button(this::showEveryOne)
.setMaterial(Material.SEA_LANTERN)
.setTitle("§aShow all players").setSlot(1);
IWidget showTeam = new Button(this::showTeamOnly)
.setMaterial(Material.GLOWSTONE)
.setTitle("§5Show only teammembers").setSlot(2);
// Add the buttons to the UI
gui.addWidget(hidePlayers);
gui.addWidget(showPlayers);
gui.addWidget(showTeam);
For some finishing touches add a descriptive item:
// Add a description item in the top that does nothing
gui.addWidget(new BasicButton((f) -> {})
.setDisplayItem(new ItemStackBuilder(Material.PAPER, 1, "§7» §ePlayerHider §7«")
.setLore(Arrays.asList("",
"§8§m--------------------",
"§eKlick on the items to",
"§ehide certain players",
"§8§m--------------------",
""))
.build())
.setSlot(3));
Now show the ui to the player:
gui.open(e.getPlayer());
}
As you can see: You are able to create a powerful GUI in just under 30 Lines of code hassle free.