ItemMenu

The API of ItemMenu is very simple: createMenu() and makeOption() plus a PlayerMenuEvent with a Enum PlayerMenuResult. The two methods belong to class ItemMenuService whose instance should be attained by the Bukkit’s ServiceManager.

Cteate Menu

1
int createMenu(Player player,String title,List<Object> options,boolean canClose)
  • player: The player who will be given this menu
  • title: The title displayed in the menu
  • options: The list of Options
  • canClose: If the player can close the menu without selecting an option
  • return: A int as the handle of the created menu, can be used to determine the menu by calling the getMenuHandle() of PlayerMenuEvent

This method create a menu and show it to the player. However, this methods cannot tell the result of the menu. To know the result, simply listen to the PlayerMenuEvent

Make simple option object

1
Object makeOption(String name,/*String[] lore,*/boolean selectable,Material material,int posX,int posY)
  • name: The name of this option(name of the item)
  • lore: Optional The lore of this option(lore of the item)
  • selectable: If this option is selectable
  • material: The material of the item of this option
  • posX: The X position of this option(leftmost==0)
  • posY: The Y position of this option(topmost==0)
  • return: The option object

Make not-so-simple option object

1
Object makeOption(String name,/*String[] lore,*/boolean selectable,ItemStack item,int posX,int posY)
  • name: The name of this option(name of the item)
  • lore: Optional The lore of this option(lore of the item)
  • selectable: If this option is selectable
  • item: The item of the option. This ItemStack's type, amount, damage and data will be used to create the option item.(Remember Enchantment will not be preserved)
  • posX: The X position of this option(leftmost==0)
  • posY: The Y position of this option(topmost==0)
  • return: The option object

Above methods are used to create options for menus. Put all options into a List<Object> and pass it to the createMenu() method to create a menu.

Listen to the event

PlayerMenuEvent

  • int getMenuHandle(): Returns the handle of the menu(it's hashcode actually) to be compared with the returns of the createMenu()
  • void getResult(): Returns the result of this event as PlayerMenuResult
    • SELECTED: The player has selected an option
    • CLOSED: The menu is closed(including player quit) by the player without selecting any option.
    • FAILED: Not used
  • String getSelected(): If an option is selected, this returns the name of the option which the player selected, else, null is returned

You must login to post a comment. Don't have an account? Register to get one!

Facts

Date created
Jan 30, 2013
Last updated
Feb 20, 2013

Author