java.lang.Object
me.eddie.inventoryguiapi.gui.guis.GUI
All Implemented Interfaces:
InventoryGUI
Direct Known Subclasses:
SharedGUI

public class GUI extends Object implements InventoryGUI
Default implementation of a GUI The state of the GUI (GUIState) is local to each session, and when a session ends (GUI closes) is lost
  • Field Details

    • AUTO_SET_SIZE

      public static final int AUTO_SET_SIZE
      See Also:
    • contentsProvider

      protected GUIContentsProvider contentsProvider
    • guiPopulator

      protected GUIPopulator guiPopulator
    • actionListeners

      protected List<GUIActionListener> actionListeners
    • guiPresenter

      protected GUIPresenter guiPresenter
    • inventoryType

      protected org.bukkit.event.inventory.InventoryType inventoryType
    • maxSize

      protected int maxSize
    • isDynamicSize

      protected boolean isDynamicSize
  • Constructor Details

    • GUI

      public GUI(org.bukkit.event.inventory.InventoryType inventoryType, int size, boolean isDynamicSize, GUIContentsProvider contentsProvider, GUIPopulator guiPopulator, GUIPresenter guiPresenter, GUIActionListener... guiActionListeners)
      Create a new GUI
      Parameters:
      inventoryType - The type of inventory to use in the created GUI
      size - The size (maximum if dynamic) to make the created GUI. Non-default sizes only supported with CHEST inventory type (Minecraft limitation)
      isDynamicSize - True if inventory should resize to wrap it's contents
      contentsProvider - The contents provider that dictates what this GUI should be showing to viewers of it
      guiPopulator - The GUIPopulator to use to position the GUIElements within the inventory to display
      guiPresenter - The GUIPresenter to use to present the computed inventory to the player
      guiActionListeners - Any ActionListeners that you want to specify. These receive GUIEvents before GUIElements do so that you can further customise the GUI's behaviour. They also receive GUIOpenEvent, GUICloseEvent and GUIUpdateEvent which GUIElements do not
    • GUI

      public GUI(org.bukkit.event.inventory.InventoryType inventoryType, int size, boolean isDynamicSize, GUIContentsProvider contentsProvider, GUIActionListener... guiActionListeners)
      Create a new GUI
      Parameters:
      inventoryType - The type of inventory to use in the created GUI
      size - The size (maximum if dynamic) to make the created GUI. Non-default sizes only supported with CHEST inventory type (Minecraft limitation)
      isDynamicSize - True if inventory should resize to wrap it's contents
      contentsProvider - The contents provider that dictates what this GUI should be showing to viewers of it
      guiActionListeners - Any ActionListeners that you want to specify. These receive GUIEvents before GUIElements do so that you can further customise the GUI's behaviour
  • Method Details

    • open

      public void open(org.bukkit.entity.Player player, int page)
      Description copied from interface: InventoryGUI
      Shows the player provided the GUI, and starts with the player viewing the given page
      Specified by:
      open in interface InventoryGUI
      Parameters:
      player - The player who should be shown the GUI
      page - The page to open the GUI on
    • fireEventThroughActionListeners

      protected void fireEventThroughActionListeners(GUIEvent event)
    • open

      public void open(org.bukkit.entity.Player player)
      Description copied from interface: InventoryGUI
      Shows the player provided the GUI, will show page 1. This method is the same as calling open(Player, 1)
      Specified by:
      open in interface InventoryGUI
      Parameters:
      player - The player who should be shown the GUI
    • createNewSession

      protected GUISession createNewSession(org.bukkit.entity.Player player, int page)
    • updateContentsAndView

      protected void updateContentsAndView(org.bukkit.entity.Player player, GUISession session)
    • updateView

      protected void updateView(org.bukkit.entity.Player player, GUISession session)
    • updateView

      public void updateView(org.bukkit.entity.Player player)
      Description copied from interface: InventoryGUI
      Will update what the viewer(s) see to match the GUI's state - if they are viewing this GUI. If the given player is not viewing this GUI then this method will silently fail
      Specified by:
      updateView in interface InventoryGUI
      Parameters:
      player - Viewer
    • updateContentsAndView

      public void updateContentsAndView(org.bukkit.entity.Player player)
      Description copied from interface: InventoryGUI
      Recalculates the GUIElements to show the player (and what their display itemstacks are) and will update what the player sees - if they are viewing this GUI. If the given player is not viewing this GUI then this method will silently fail
      Specified by:
      updateContentsAndView in interface InventoryGUI
      Parameters:
      player - The player to use to recalculate the GUIElements being displayed
    • handleBukkitEvent

      public void handleBukkitEvent(org.bukkit.event.Event event, GUISession session)
      Description copied from interface: InventoryGUI
      Handle the given Bukkit event, for example a ClickEvent
      Specified by:
      handleBukkitEvent in interface InventoryGUI
      Parameters:
      event - The event to handle
      session - The GUI Session that should respond to the event
    • handleAutoInsertAsIndividualActions

      protected void handleAutoInsertAsIndividualActions(org.bukkit.entity.Player viewer, InventoryState inventoryState, GUISession session, org.bukkit.inventory.Inventory destInv, org.bukkit.event.inventory.InventoryClickEvent shiftClickEvent)
    • fireEvent

      protected <T> void fireEvent(GUIEvent guiEvent, GUIElement guiElement, T receivedEvent)
    • handleBedrockResponse

      public void handleBedrockResponse(GUISession session, org.bukkit.entity.Player player, int clickedButtonId)
      Description copied from interface: InventoryGUI
      Handle a Bedrock form response
      Specified by:
      handleBedrockResponse in interface InventoryGUI
      Parameters:
      session - The GUI Session that should respond to the event
      player - Player that opened the dialog
      clickedButtonId - ID of clicked button, -1 if no button was clicked
    • getContentsProvider

      public GUIContentsProvider getContentsProvider()
      Get the ContentsProvider associated with calculating what GUIElements to display in this GUI
      Returns:
      The ContentsProvider
    • getGuiPopulator

      public GUIPopulator getGuiPopulator()
      Get the GUIPopulator associated with calculating the layout of GUIElements to display in this GUI
      Returns:
      The GUIPopulator
    • getGuiPresenter

      public GUIPresenter getGuiPresenter()
      Get the GUIPresenter associated with displaying this GUI
      Returns:
      The GUIPresenter
    • getInventoryType

      public org.bukkit.event.inventory.InventoryType getInventoryType()
      Description copied from interface: InventoryGUI
      Get the inventory type used by this GUI to display items to viewers
      Specified by:
      getInventoryType in interface InventoryGUI
      Returns:
      The InventoryType
    • getMaximumGUISize

      public int getMaximumGUISize()
      Description copied from interface: InventoryGUI
      Get the maximum size that this GUI can be before extra elements will flow onto new pages. Note, this size has to be compatible with the possible sizes of the InventoryType specified. Eg. for chests it has to be a multiple of 9.
      Specified by:
      getMaximumGUISize in interface InventoryGUI
      Returns:
      The maximum size that this GUI can be.
    • isGUISizeDynamic

      public boolean isGUISizeDynamic()
      Description copied from interface: InventoryGUI
      Whether or not this GUI should re-scale it's size to wrap it's current contents or if it should always be the maximum size
      Specified by:
      isGUISizeDynamic in interface InventoryGUI
      Returns:
      True if the GUI should re-scale to wrap it's current contents, False otherwise