Class InventoryMenu

java.lang.Object
net.citizensnpcs.api.gui.InventoryMenu
All Implemented Interfaces:
Runnable, Listener

public class InventoryMenu extends Object implements Listener, Runnable
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 InventoryMenuPages, 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 InventoryMenuSlots 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. InventoryMenuPages 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 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

      public void close(HumanEntity entity)
      Closes the GUI for just a specific Player.
    • onInventoryClick

      public void onInventoryClick(InventoryClickEvent event)
    • onInventoryClose

      public void onInventoryClose(InventoryCloseEvent event)
    • onInventoryDrag

      public void onInventoryDrag(InventoryDragEvent event)
    • present

      public void present(HumanEntity player)
      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()
      Specified by:
      run in interface Runnable
    • transition

      public void transition(Class<? extends InventoryMenuPage> clazz)
      Transition to another page. Adds the previous page to a stack which will be returned to when the current page is closed.
    • transition

      public void transition(Class<? extends InventoryMenuPage> clazz, Map<String,Object> context)
      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

      public void transition(InventoryMenuPage instance)
      Transition to another page. Adds the previous page to a stack which will be returned to when the current page is closed.
    • transition

      public void transition(InventoryMenuPage instance, Map<String,Object> context)
      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

      public static InventoryMenu create(Class<? extends InventoryMenuPage> clazz)
      Create an inventory menu instance starting at the given page.
    • create

      public static InventoryMenu create(InventoryMenuPage instance)
      Create an inventory menu instance starting at the given page.
    • createSelfRegistered

      public 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.
    • createSelfRegistered

      public 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.
    • 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.