API for creating GUI menus in Minecraft
GUIEngine is a lightweight, flexible API for creating interactive GUI menus in Minecraft Paper servers (1.21.4). Instead of writing repetitive inventory code for each menu in your plugins, GUIEngine provides a clean, reusable system to create rich interactive interfaces.
GUIEngine is designed as a dependency for other plugins, providing a standardized way to:
It functions similar to other utility plugins like Vault or ProtocolLib, but focused exclusively on GUI management.
GUIEngine consists of five core components:
The main plugin class that initializes the system, registers event listeners, and provides access points for other plugins.
Represents an inventory menu with slots for buttons. Each GUI handles its own layout and button mapping.
Interactive items within menus that can trigger actions when clicked. Buttons can execute code, send messages, open other menus, etc.
Keeps track of which menu is open for each player and manages the opening/closing of menus.
Intercepts inventory events and routes them to the appropriate GUI components.
First, add GUIEngine as a dependency in your plugin.yml:
depend: [GUIEngine]
Then, add it to your Maven/Gradle build file.
For Maven:
<dependencies>
<dependency>
<groupId>com.gui.engine</groupId>
<artifactId>gui-engine</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Here's a simple example showing how to create and display a menu:
// Create a new GUI with 3 rows (27 slots)
GUI myMenu = new GUI("§6§lMy Menu", 3);
// Add a button that sends a message when clicked
GUIButton messageButton = new GUIButton(
Material.PAPER,
"§e§lClick Me",
Arrays.asList("§7Click to receive", "§7a message"),
(player, gui, button, slot) -> {
player.sendMessage("§aYou clicked the button!");
return true;
}
);
// Add a button that closes the menu
GUIButton closeButton = new GUIButton(
Material.BARRIER,
"§c§lClose",
(player, gui, button, slot) -> {
player.closeInventory();
return true;
}
);
// Place buttons in specific slots
myMenu.setButton(13, messageButton);
myMenu.setButton(26, closeButton);
// Open the menu for a player
myMenu.open(player);
You can also use the builder pattern for cleaner menu creation:
GUI menu = new GUI.Builder()
.title("§6§lMy Menu")
.rows(3)
.build();
// Then add buttons and open as normal
Buttons can update themselves in response to clicks:
GUIButton counterButton = new GUIButton(
Material.EMERALD,
"§a§lClicks: §f0",
(player, gui, button, slot) -> {
// Extract current count from name
String name = ChatColor.stripColor(button.getItem().getItemMeta().getDisplayName());
int count = Integer.parseInt(name.split(": ")[1]) + 1;
// Update button name
button.setName("§a§lClicks: §f" + count);
// Update the inventory display
gui.updateInventory();
return true;
}
);
You can easily create navigation systems between menus:
// In your main menu creation:
GUIButton settingsButton = new GUIButton(
Material.REDSTONE_TORCH,
"§b§lSettings",
(player, gui, button, slot) -> {
openSettingsMenu(player); // Your method to create/open settings menu
return true;
}
);
// And in your settings menu:
GUIButton backButton = new GUIButton(
Material.ARROW,
"§e§lBack",
(player, gui, button, slot) -> {
openMainMenu(player); // Your method to create/open main menu
return true;
}
);
You can create different types of button actions:
// Teleport button
GUIButton teleportButton = new GUIButton(
Material.ENDER_PEARL,
"§5§lTeleport to Spawn",
(player, gui, button, slot) -> {
player.closeInventory();
player.teleport(player.getWorld().getSpawnLocation());
player.sendMessage("§aTeleported to spawn!");
return true;
}
);
// Command execution button
GUIButton commandButton = new GUIButton(
Material.COMMAND_BLOCK,
"§c§lExecute Command",
(player, gui, button, slot) -> {
player.closeInventory();
player.performCommand("spawn");
return true;
}
);
Use the GUIButton builder for even cleaner button creation:
GUIButton button = new GUIButton.Builder()
.material(Material.DIAMOND)
.name("§b§lPremium Features")
.lore("§7Click to view premium options")
.lore("§7Cost: $10")
.onClick((player, gui, button, slot) -> {
// Handle click
return true;
})
.build();
See the ExampleGUI.java class in the GUIEngine source code for a complete example of creating menus, submenus, and various button types.
GUIEngine is licensed under the MIT License. Feel free to use, modify, and distribute as needed.