Package net.citizensnpcs.api.gui
Class InventoryMenu
java.lang.Object
net.citizensnpcs.api.gui.InventoryMenu
A container class for Inventory GUIs. Expects
onInventoryClick(InventoryClickEvent)
and
onInventoryClose(InventoryCloseEvent)
to be called by the user (or registered with the event listener
system). Optionally, run()
can also be called every tick.
Inventory GUIs are defined as a stack of InventoryMenuPage
s, each of which represents a distinct inventory
that is transitioned between using either code or user clicks using the InventoryMenuTransition
class. Each
InventoryMenuPage
should define a Menu
annotation at the class level.
Each page has a number of InventoryMenuSlot
s which define attributes such as default slot item,
interactibility, etc.
You can define sets of slots and transitions using InventoryMenuPattern
.
For each concrete class of slot/transition/pattern there is a corresponding annotation that is defined.
InventoryMenuPage
s can either annotate specific instances of these concrete classes which will be injected at
runtime or simply place them at the method/class level.
Instances of global/contextual variables can be injected dynamically via InjectContext
which sources
variables from the MenuContext
.-
Constructor Summary
ConstructorDescriptionInventoryMenu
(net.citizensnpcs.api.gui.InventoryMenu.InventoryMenuInfo info, InventoryMenuPage instance) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the GUI and all associated viewer inventories.void
close
(HumanEntity entity) Closes the GUI for just a specific Player.static InventoryMenu
create
(Class<? extends InventoryMenuPage> clazz) Create an inventory menu instance starting at the given page.static InventoryMenu
create
(InventoryMenuPage instance) Create an inventory menu instance starting at the given page.static InventoryMenu
createSelfRegistered
(Class<? extends InventoryMenuPage> clazz) Creates an inventory menu instance starting at the given page that registers events and deregisters events when the menu is closed.static InventoryMenu
createSelfRegistered
(InventoryMenuPage instance) Creates an inventory menu instance starting at the given page that registers events and deregisters events when the menu is closed.static InventoryMenu
createWithContext
(Class<? extends InventoryMenuPage> clazz, Map<String, Object> context) Create an inventory menu instance starting at the given page and with the initial context.void
void
void
void
present
(HumanEntity player) Display the menu to the given player.void
run()
void
transition
(Class<? extends InventoryMenuPage> clazz) Transition to another page.void
transition
(Class<? extends InventoryMenuPage> clazz, Map<String, Object> context) Transition to another page with context.void
transition
(InventoryMenuPage instance) Transition to another page.void
transition
(InventoryMenuPage instance, Map<String, Object> context) Transition to another page with context.void
-
Constructor Details
-
InventoryMenu
public InventoryMenu(net.citizensnpcs.api.gui.InventoryMenu.InventoryMenuInfo info, InventoryMenuPage instance)
-
-
Method Details
-
close
public void close()Closes the GUI and all associated viewer inventories. -
close
Closes the GUI for just a specific Player. -
onInventoryClick
-
onInventoryClose
-
onInventoryDrag
-
present
Display the menu to the given player. Multiple players can be shown the same menu, but transitions will affect all players and the inventory is shared. -
run
public void run() -
transition
Transition to another page. Adds the previous page to a stack which will be returned to when the current page is closed. -
transition
Transition to another page with context. Adds the previous page to a stack which will be returned to when the current page is closed. -
transition
Transition to another page. Adds the previous page to a stack which will be returned to when the current page is closed. -
transition
Transition to another page with context. Adds the previous page to a stack which will be returned to when the current page is closed. -
transitionBack
public void transitionBack() -
create
Create an inventory menu instance starting at the given page. -
create
Create an inventory menu instance starting at the given page. -
createSelfRegistered
Creates an inventory menu instance starting at the given page that registers events and deregisters events when the menu is closed. -
createSelfRegistered
Creates an inventory menu instance starting at the given page that registers events and deregisters events when the menu is closed. -
createWithContext
public static InventoryMenu createWithContext(Class<? extends InventoryMenuPage> clazz, Map<String, Object> context) Create an inventory menu instance starting at the given page and with the initial context.
-