MenuAPI
The menu uses the inventory system to create an interactive menu viewable by the player.
Imports:
import com.adamantdreamer.ui.menu.Menu;
First an MenuHandler class must be created to handle any interactions with the Menu:
import com.adamantdreamer.ui.menu.MenuHandler; import org.bukkit.event.Event; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; public class MyMenuHandler implements MenuHandler { @Override public Event.Result onClick(InventoryClickEvent event) { // The InventoryClickEvent is directly called from bukkit's API, and //can tell what was clicked and how, allowing the plugin to determine //the course of action. // The DENY response will not allow any items to moved around //the menu or player's inventory, though others may be useful for //certain actions and menu types. Event.Result.DENY; } @Override public void onClose(InventoryCloseEvent event) { // This lets the plugin know the player has closed the menu, and //can respond with any appropriate actions. } }
Then, the menu is created and linked to the handler, which can be then shown to any player:
Menu hub = new Menu("Welcome to the Hub", new MyMenuHandler()); hub.add(new ItemStack(Material.BED), "Home", "Teleports to your home location."); hub.add(new ItemStack(Material.Beacon), "Spawn", "Warps you to the spawn point."); hub.show(player);
Notes:
- A menu can be stored to view by multiple players. When viewed by a player, an ActiveMenu is made for their perspective, so no changes on one player's menu will affect the menu object as a whole.
- If no MenuHandler is used, an non-interactive menu appears instead (any clicking will return a DENY result), useful for displaying large amounts of information.
Any chance we could see a more detailed tutorial in the future?
You lose "return" before "Event.Result.DENY"
A good idea would be to implement your own event and call it, including easy access methods such as event.getTitle() which would get you the title of the item, like "Home", and event.getPlayer() would be neat too.
Otherwise, great!
Is it possible to have several MenuHolders? Because I want to make a plugin, where custom inventories hold navigation. The Hive and Mineplex are some examples of what I'm hoping to achieve with the inventories.