Class GUIBuilder

java.lang.Object
me.eddie.inventoryguiapi.gui.guis.GUIBuilder

public class GUIBuilder extends Object
Builder for the constructing an instance of one of the default GUI implementations
  • Constructor Details

    • GUIBuilder

      public GUIBuilder()
      Create a new GUIBuilder, used for building a new InventoryGUI that uses the default GUI implementation
  • Method Details

    • guiStateBehaviour

      public GUIBuilder guiStateBehaviour(GUIBuilder.GUIStateBehaviour behaviour)
      Define how the GUIState should be handled. A value of GUIBuilder.GUIStateBehaviour.LOCAL_TO_SESSION will mean the default GUI implementation is used, with this implementation the GUIState is lost when the session ends (GUI closes). A value of GUIBuilder.GUIStateBehaviour.BOUND_TO_GUI will mean the default SharedGUI implementation is used, with this implementation the GUIState is bound to the GUI and is persistent. This means all viewers will see the same GUIState and it persists beyond the GUI closing.
      Parameters:
      behaviour - How the GUIState should behave
      Returns:
      Returns self
    • presenter

      public GUIBuilder presenter(GUIPresenter presenter)
      Specify a custom GUIPresenter to use with this GUI A GUIPresenter takes the calculated InventoryState that the GUI should currently be displaying and displays it to the end-user. A custom GUIPresenter will allow you to customize how your GUI is viewed. For almost all use cases it is recommended to use the default GUIPresenter (Don't call this method)
      Parameters:
      presenter - The custom GUIPresenter to use, or null (or not specified) if you want the default one
      Returns:
      Returns self
    • populator

      public GUIBuilder populator(GUIPopulator populator)
      Specify a custom GUIPopulator to use with this GUI. A GUIPopulator calculates the final position that each element should be in within the displayed GUI before it is rendered. Specify a custom GUIPopulator to make your GUI use a complex custom layout. (Simple layout changes can be done by manipulating the desired slots of GUIElements)
      Parameters:
      populator - The custom GUIPopulator to use, or null (Or not specified) if you want the default one
      Returns:
      Returns self
    • actionListeners

      public GUIBuilder actionListeners(GUIActionListener... actionListeners)
      Specify action listeners for this GUI. ActionListeners receive GUI events (Eg. open, close, place item) before GUIElements do (But after they're fired through the Bukkit event system). These are ideal for adding GUI specific event handling. For example you may want to, when a GUI closes, save what is input into an InputSlot.
      Parameters:
      actionListeners - The ActionListeners that should listen to actions with this GUI
      Returns:
      Returns self
    • size

      public GUIBuilder size(int size)
      Set the size this GUI should be for each page. With a dynamically re-sizing GUI this is the maximum size
      Parameters:
      size - The size or maximum size of this GUI
      Returns:
      Returns self
    • dynamicallyResizeToWrapContent

      public GUIBuilder dynamicallyResizeToWrapContent(boolean resize)
      Set whether or not this inventory should automatically re-size to wrap it's contents. (Up to the maximum size). When automatic re-sizing is enabled, the size specified to the builder is treated as the maximum size of a GUI page.
      Parameters:
      resize - True if GUI should dynamically resize
      Returns:
      Returns self
    • inventoryType

      public GUIBuilder inventoryType(org.bukkit.event.inventory.InventoryType inventoryType)
      Sets the type of the inventory the GUI displays. This must be type CHEST if you wish to have a dynamically sized GUI
      Parameters:
      inventoryType - The type of inventory
      Returns:
      Returns self
    • contents

      public GUIBuilder contents(String title, List<GUIElement> elements, boolean paginate, boolean showPageNum, boolean showPageCount)
      Specify what GUIElements this GUI should display and the title of the GUI. This is useful for static GUIs. For GUIs that need to show different GUIElements to different viewers, or that need GUISession information to determine which GUIElements to display a GUIContentsProvider should be used instead.
      Parameters:
      title - The title of the GUI
      elements - The list of elements to display
      paginate - Whether or not to automatically split these GUIElements into pages
      showPageNum - Whether or not to show the page number in the title, ignored if paginate is False
      showPageCount - Whether or not to show the page count in the title, ignored if paginate is False
      Returns:
      Returns self
    • inventoryContents

      public GUIBuilder inventoryContents(String title, List<GUIElement> elements, boolean paginate, boolean showPageNum, boolean showPageCount)
      Specify what GUIElements this GUI should display and the title of the GUI if Inventory-based.
      Parameters:
      title - The title of the GUI
      elements - The list of elements to display
      paginate - Whether or not to automatically split these GUIElements into pages
      showPageNum - Whether or not to show the page number in the title, ignored if paginate is False
      showPageCount - Whether or not to show the page count in the title, ignored if paginate is False
      Returns:
      Returns self
    • bedrockContents

      public GUIBuilder bedrockContents(String title, List<GUIElement> elements, boolean paginate, boolean showPageNum, boolean showPageCount)
      Specify what GUIElements this GUI should display and the title of the GUI if Bedrock Forms-based.
      Parameters:
      title - The title of the GUI
      elements - The list of elements to display
      paginate - Whether or not to automatically split these GUIElements into pages
      showPageNum - Whether or not to show the page number in the title, ignored if paginate is False
      showPageCount - Whether or not to show the page count in the title, ignored if paginate is False
      Returns:
      Returns self
    • paginatingContentsProvider

      public GUIBuilder paginatingContentsProvider(PaginatingGUIContentsProvider contentsProvider)
      Specify the PaginatingGUIContentsProvider this GUI should use. A contents provider defines what GUIElements should be displayed on each GUI page and for which viewer. This method is the same as calling contentsProvider(GUIContentsProvider) with a PaginatingContentsProvider PaginatingContentsProvider is an abstract class that handles splitting a list of GUIElements into pages to display. This is useful if you have a list of GUIElemenets to display and want them automatically sorted into pages for you. To use PaginatingContentsProvider, extend the class and implement the methods marked as abstract.
      Parameters:
      contentsProvider - The PaginatingContentsProvider for this GUI
      Returns:
      Returns self
    • contentsProvider

      public GUIBuilder contentsProvider(GUIContentsProvider contentsProvider)
      Specify the GUIContentsProvider this GUI should use. A contents provider defines what GUIElements should be displayed on each GUI page and for which viewer.
      Parameters:
      contentsProvider - The ContentsProvider for this GUI
      Returns:
      Returns self
    • build

      public InventoryGUI build()