public final class MenuBuilder extends Object
| Modifier and Type | Field and Description |
|---|---|
protected Map<Integer,ClickAction> |
actions
MenuAction to slot mappings.
|
protected boolean |
allowItemPickup
Allow items to be removed from the menu inventory.
|
protected boolean |
allowLowerInvShiftClick
Allow shift-clicking of items from the lower inventory.
|
protected boolean |
cancelLowerInvClick
Determine whether clicks on the lower inventory should be cancelled.
|
protected CloseAction |
closeAction
Callback to run on menu close.
|
protected org.bukkit.inventory.ItemStack[] |
initialContents
Initial contents of the menu inventory before elements are added.
|
protected Map<Integer,MenuElement> |
items
ItemStack to slot mappings.
|
Menu.InventoryRows |
numberOfRows
Describes the number of rows and slots in the final Menu.
|
protected String |
title
Title of the final Menu inventory.
|
| Constructor and Description |
|---|
MenuBuilder(Menu.InventoryRows rows,
String title)
Create a new MenuBuilder with a number of rows and a title.
|
MenuBuilder(Menu.InventoryRows rows,
String title,
org.bukkit.inventory.ItemStack[] initialContents)
Create a new MenuBuilder with rows, title and initial contents.
|
| Modifier and Type | Method and Description |
|---|---|
ElementBuilder |
addElement(org.bukkit.inventory.ItemStack item)
Add a previously styled ItemStack directly to the menu.
|
ElementBuilder |
addElement(org.bukkit.inventory.ItemStack item,
String text,
String... lore)
Add an ItemStack to the menu of specified display name and lore.
|
MenuBuilder |
allowLowerShiftClicks(boolean toAllow)
Should shift-clicks on the lower inventory be allowed?
|
MenuBuilder |
cancelLowerInventoryClicks(boolean toCancel)
Should ALL clicks on the lower inventory be cancelled as well?
|
Menu |
create(org.bukkit.plugin.java.JavaPlugin yourPlugin)
Create the Menu specified by the contents of this builder.
|
MenuBuilder |
defaultClickBehavior(boolean allowPickup)
Determine default pickup behavior when clicking ItemStacks.
|
MenuBuilder |
setCloseAction(CloseAction closeAction)
Define a callback to run on inventory close.
|
MenuBuilder |
setInitialContents(org.bukkit.inventory.ItemStack[] contents)
Set the initial contents of the inventory.
|
MenuBuilder |
setTitle(String title)
Set a new title for the menu.
|
public final Menu.InventoryRows numberOfRows
protected final Map<Integer,MenuElement> items
protected final Map<Integer,ClickAction> actions
protected CloseAction closeAction
protected String title
protected org.bukkit.inventory.ItemStack[] initialContents
protected boolean cancelLowerInvClick
protected boolean allowItemPickup
protected boolean allowLowerInvShiftClick
public MenuBuilder(Menu.InventoryRows rows, String title)
Menu will start out blank and elements will added.
rows - number of rows in final Inventorytitle - Title of generated inventorypublic MenuBuilder(Menu.InventoryRows rows, String title, org.bukkit.inventory.ItemStack[] initialContents)
rows - number of rows in final Inventorytitle - Title of generated inventoryinitialContents - an array of items to prefill the menu withIllegalArgumentException - if initialContents.length > slotspublic MenuBuilder setCloseAction(CloseAction closeAction)
Null by default; set to null to disable.
closeAction - a CloseAction or null for nonepublic MenuBuilder setTitle(String title)
title - a new title for the generate menupublic MenuBuilder setInitialContents(org.bukkit.inventory.ItemStack[] contents)
This happens after creation of the inventory but before menu elements are processed.
contents - an array of itemspublic MenuBuilder defaultClickBehavior(boolean allowPickup)
Defaults to false. You can set this true and set different pickup logic for specific elements (for instance, an item vault system with pagination, possibly a sub-menu).
allowPickup - whether to allow item pickuppublic MenuBuilder cancelLowerInventoryClicks(boolean toCancel)
False by default.
toCancel - true to cancel clicks on lowerpublic MenuBuilder allowLowerShiftClicks(boolean toAllow)
Care should be taken to ensure menu elements aren't altered by items provided. Defaults to false.
toAllow - allow shift-clicks on itempublic ElementBuilder addElement(org.bukkit.inventory.ItemStack item)
This is useful if you're used to managing your own custom items. Your item will not be altered.
item - item to addpublic ElementBuilder addElement(org.bukkit.inventory.ItemStack item, String text, String... lore)
Recommended if you are not used to altering ItemMetas. Handles styling for you.
item - item to addtext - display name of itemlore - optional lore to add as varargspublic Menu create(org.bukkit.plugin.java.JavaPlugin yourPlugin)
Requires plugin reference for event syncing.
yourPlugin - an instance of your pluginCopyright © 2021. All rights reserved.