Class GUIElementFactory

java.lang.Object
me.eddie.inventoryguiapi.gui.elements.GUIElementFactory

public class GUIElementFactory extends Object
Some helpful methods for creating common GUIElements
  • Constructor Details

    • GUIElementFactory

      public GUIElementFactory()
  • Method Details

    • formatItem

      public static org.bukkit.inventory.ItemStack formatItem(org.bukkit.inventory.ItemStack base, String displayName, String... lore)
      Will take a given ItemStack and change it's lore and display name. The edited ItemStack is then returned. This is a convenience method that saves you from the work of manipulating ItemMeta.
      Parameters:
      base - The base ItemStack to modify
      displayName - The display name to set, can be colored (Using Bukkit's ChatColor)
      lore - The lore to set, canbe colored (Using Bukkit'S ChatColor)
      Returns:
      The formatted item
    • createInputSlot

      public static InputSlot createInputSlot(String uniqueInputSlotID, InputSlot.ActionHandler actionHandler)
      Create an InputSlot - A GUIElement that accepts user input This InputSlot will have no preference for which slot it should be displayed in. If you wish to specify a slot, use createInputSlot(String, int, InputSlot.ActionHandler) Use InputSlot.setCurrentItem(me.eddie.inventoryguiapi.gui.session.GUISession, ItemStack) to change the item currently input post-creation. Note that this change will not be visible to viewers until their view has been updated. (If done within a ContentsProvider then the view is updated for you)
      Parameters:
      uniqueInputSlotID - The unique ID that references this input slot. This is used for tracking what item is input into slot throughout the GUISession.
      actionHandler - ActionHandler that lets you manipulate the behaviour of this input slot. Eg. prevent certain items being input into the slot (By cancelling GUIEvent and bukkit event within the handler)
      Returns:
      The created InputSlot
    • createInputSlot

      public static InputSlot createInputSlot(String uniqueInputSlotID, int desiredSlot, InputSlot.ActionHandler actionHandler)
      Create an InputSlot - A GUIElement that accepts user input Use InputSlot.setCurrentItem(me.eddie.inventoryguiapi.gui.session.GUISession, ItemStack) to change the item currently input post-creation. Note that this change will not be visible to viewers until their view has been updated. (If done within a ContentsProvider then the view is updated for you)
      Parameters:
      uniqueInputSlotID - The unique ID that references this input slot. This is used for tracking what item is input into slot throughout the GUISession.
      desiredSlot - The slot you wish for this GUIElement to be placed into in the GUI. Use createInputSlot(String, InputSlot.ActionHandler) if you do not care about the placement position of this item.
      actionHandler - ActionHandler that lets you manipulate the behaviour of this input slot. Eg. prevent certain items being input into the slot (By cancelling GUIEvent and bukkit event within the handler)
      Returns:
      The created InputSlot
    • createActionItem

      public static ActionItem createActionItem(org.bukkit.inventory.ItemStack displayItem, ActionItem.ActionHandler actionHandler)
      Create an ActionItem - A GUIElement that when clicked performs an action. This ActionItem will have no preference for which slot it should be displayed in. If you wish to specify a slot, use createActionItem(int, ItemStack, ActionItem.ActionHandler)
      Parameters:
      displayItem - The item to display in the slot that this GUIElement occupies.
      actionHandler - ActionHandler that defines what this ActionItem does when clicked. To re-calculate the contents to be displayed, call to InventoryGUI.updateContentsAndView(Player)
      Returns:
      The created ActionItem
    • createActionItem

      public static ActionItem createActionItem(org.bukkit.inventory.ItemStack displayItem, Callback<org.bukkit.entity.Player> onClick)
      Create an ActionItem - A GUIElement that when clicked performs an action. This ActionItem will have no preference for which slot it should be displayed in. If you wish to specify a slot, use createActionItem(int, ItemStack, ActionItem.ActionHandler)
      Parameters:
      displayItem - The item to display in the slot that this GUIElement occupies.
      onClick - Runnable that is ran when item clicked. To re-calculate the contents to be displayed, call to InventoryGUI.updateContentsAndView(Player)
      Returns:
      The created ActionItem
    • createActionItem

      public static ActionItem createActionItem(int desiredSlot, org.bukkit.inventory.ItemStack displayItem, Callback<org.bukkit.entity.Player> onClick)
      Create an ActionItem - A GUIElement that when clicked performs an action
      Parameters:
      desiredSlot - The slot you wish for this GUIElement to be placed into in the GUI. Use createActionItem(ItemStack, ActionItem.ActionHandler) if you do not care about the placement position of this item.
      displayItem - The item to display in the slot that this GUIElement occupies.
      onClick - Runnable that is ran when item clicked. To re-calculate the contents to be displayed, call to InventoryGUI.updateContentsAndView(Player)
      Returns:
      The created ActionItem
    • createActionItem

      public static ActionItem createActionItem(int desiredSlot, org.bukkit.inventory.ItemStack displayItem, Callback<org.bukkit.entity.Player> onClick, FormImage formImage)
      Create an ActionItem - A GUIElement that when clicked performs an action
      Parameters:
      desiredSlot - The slot you wish for this GUIElement to be placed into in the GUI. Use createActionItem(ItemStack, ActionItem.ActionHandler) if you do not care about the placement position of this item.
      displayItem - The item to display in the slot that this GUIElement occupies.
      onClick - Runnable that is ran when item clicked. To re-calculate the contents to be displayed, call to InventoryGUI.updateContentsAndView(Player)
      formImage - Image to use in Bedrock Form GUI, in place of a texture of provided displayItem
      Returns:
      The created ActionItem
    • createActionItem

      public static ActionItem createActionItem(int desiredSlot, org.bukkit.inventory.ItemStack displayItem, ActionItem.ActionHandler actionHandler)
      Create an ActionItem - A GUIElement that when clicked performs an action
      Parameters:
      desiredSlot - The slot you wish for this GUIElement to be placed into in the GUI. Use createActionItem(ItemStack, ActionItem.ActionHandler) if you do not care about the placement position of this item.
      displayItem - The item to display in the slot that this GUIElement occupies.
      actionHandler - ActionHandler that defines what this ActionItem does when clicked. To re-calculate the contents to be displayed, call to InventoryGUI.updateContentsAndView(Player)
      Returns:
      The created ActionItem
    • createActionItem

      public static ActionItem createActionItem(int desiredSlot, org.bukkit.inventory.ItemStack displayItem, ActionItem.ActionHandler actionHandler, FormImage formImage)
      Create an ActionItem - A GUIElement that when clicked performs an action
      Parameters:
      desiredSlot - The slot you wish for this GUIElement to be placed into in the GUI. Use createActionItem(ItemStack, ActionItem.ActionHandler) if you do not care about the placement position of this item.
      displayItem - The item to display in the slot that this GUIElement occupies.
      actionHandler - ActionHandler that defines what this ActionItem does when clicked. To re-calculate the contents to be displayed, call to InventoryGUI.updateContentsAndView(Player)
      formImage - Image to use in Bedrock Form GUI, in place of a texture of provided displayItem
      Returns:
      The created ActionItem
    • createLabelItem

      public static LabelItem createLabelItem(org.bukkit.inventory.ItemStack displayItem)
      Create a LabelItem - A GUIElement that displays text This LabelItem will have no preference for which slot it should be displayed in. If you wish to specify a slot, use createLabelItem(int, ItemStack)
      Parameters:
      displayItem - The item to display in the slot that this GUIElement occupies.
      Returns:
      The created LabelItem
    • createLabelItem

      public static LabelItem createLabelItem(int desiredSlot, org.bukkit.inventory.ItemStack displayItem)
      Create a LabelItem - A GUIElement that displays text
      Parameters:
      desiredSlot - The slot you wish for this GUIElement to be placed into in the GUI. Use createActionItem(ItemStack, ActionItem.ActionHandler) if you do not care about the placement position of this item.
      displayItem - The item to display in the slot that this GUIElement occupies.
      Returns:
      The created LabelItem