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.

Comments

Posts Quoted:
Reply
Clear All Quotes