Interface GUI

All Superinterfaces:
GUIParent
All Known Implementing Classes:
BaseGUI, PagedGUI, ScrollGUI, SimpleGUI, SimplePagedItemsGUI, SimplePagedNestedGUI, SimpleScrollItemsGUI, SimpleScrollNestedGUI, SimpleScrollVIGUI, SimpleTabGUI, TabGUI

public interface GUI extends GUIParent
A GUI is a container for width * height SlotElements.
Each SlotElement can either be an Item, a reference to a VirtualInventory's or another GUI's slot index.
A GUI is not an Inventory, nor does it access one. It just contains SlotElements and their positions.
In order to create an Inventory which is visible to players, you will need to use a Window.
See Also:
  • Method Details

    • getSize

      int getSize()
      Gets the size of the GUI.
      Returns:
      The size of the gui.
    • getWidth

      int getWidth()
      Gets the width of the GUI
      Returns:
      The width of the GUI
    • getHeight

      int getHeight()
      Gets the height of the GUI
      Returns:
      The height of the GUI
    • setSlotElement

      void setSlotElement(int x, int y, @Nullable @Nullable SlotElement slotElement)
      Sets the SlotElement on these coordinates. If you need to set an Item, please use setItem(int, int, Item) instead.
      Parameters:
      x - The x coordinate
      y - The y coordinate
      slotElement - The SlotElement to be placed there.
    • setSlotElement

      void setSlotElement(int index, @Nullable @Nullable SlotElement slotElement)
      Sets the SlotElement on these coordinates. If you need to set an Item, please use setItem(int, Item) instead.
      Parameters:
      index - The slot index
      slotElement - The SlotElement to be placed there.
    • getSlotElement

      SlotElement getSlotElement(int x, int y)
      Gets the SlotElement on these coordinates.
      Parameters:
      x - The x coordinate
      y - The y coordinate
      Returns:
      The SlotElement placed there
    • getSlotElement

      SlotElement getSlotElement(int index)
      Gets the SlotElement placed on that slot.
      Parameters:
      index - The slot index
      Returns:
      The SlotElement placed on that slot
    • hasSlotElement

      boolean hasSlotElement(int x, int y)
      Gets if there is a SlotElement on these coordinates.
      Parameters:
      x - The x coordinate
      y - The y coordinate
      Returns:
      If there is a SlotElement placed there
    • hasSlotElement

      boolean hasSlotElement(int index)
      Gets if there is a SlotElement placed on that slot.
      Parameters:
      index - The slot index
      Returns:
      If there is a SlotElement placed there
    • getSlotElements

      SlotElement[] getSlotElements()
      Gets all SlotElements of this GUI in an Array.
      Returns:
      All SlotElements of this GUI
    • setItem

      void setItem(int x, int y, Item item)
      Sets the Item on these coordinates.
      Parameters:
      x - The x coordinate
      y - The y coordinate
      item - The Item that should be placed on these coordinates or null to remove the Item that is currently there.
    • setItem

      void setItem(int index, Item item)
      Sets the Item on that slot
      Parameters:
      index - The slot index
      item - The Item that should be placed on that slot or null to remove the Item that is currently there.
    • getItem

      Item getItem(int x, int y)
      Gets the Item on these coordinates.
      Parameters:
      x - The x coordinate
      y - The y coordinate
      Returns:
      The Item which is placed on that slot or null if there isn't one
    • getItem

      Item getItem(int index)
      Gets the Item placed on that slot.
      Parameters:
      index - The slot index
      Returns:
      The Item which is placed on that slot or null if there isn't one
    • addItems

      void addItems(@NotNull @NotNull Item... items)
      Adds Items to the gui.
      Parameters:
      items - The Items that should be added to the gui
    • getBackground

      ItemProvider getBackground()
      Gets the ItemProvider that will be used if nothing else is placed on a slot.
      Returns:
      The ItemProvider
    • setBackground

      void setBackground(@Nullable @Nullable ItemProvider itemProvider)
      Sets the ItemProvider that will be used if nothing else is placed on a slot.
      Parameters:
      itemProvider - The ItemProvider
    • remove

      void remove(int x, int y)
      Removes an Item by its coordinates.
      Parameters:
      x - The x coordinate
      y - The y coordinate
    • remove

      void remove(int index)
      Remove the Item which are placed on these slots.
      Parameters:
      index - The slot index of the Items that should be removed
    • applyStructure

      void applyStructure(Structure structure)
      Applies the given Structure to the GUI.
      Parameters:
      structure - The structure
    • handleClick

      void handleClick(int slot, org.bukkit.entity.Player player, org.bukkit.event.inventory.ClickType clickType, org.bukkit.event.inventory.InventoryClickEvent event)
      A method called if a slot in the Inventory has been clicked.
      Parameters:
      slot - The slot that has been clicked
      player - The Player that clicked
      clickType - The ClickType
      event - The InventoryClickEvent
    • handleItemShift

      void handleItemShift(org.bukkit.event.inventory.InventoryClickEvent event)
      A method called when an ItemStack has been shift-clicked into this GUI.
      Parameters:
      event - The InventoryClickEvent associated with this action
    • handleItemDrag

      boolean handleItemDrag(UpdateReason updateReason, int slot, org.bukkit.inventory.ItemStack oldStack, org.bukkit.inventory.ItemStack newStack)
      A method called when an ItemStack has been dragged over the GUI.
      Parameters:
      updateReason - The reason for this item update.
      slot - The slot index
      oldStack - The ItemStack that was previously on that slot
      newStack - The new ItemStack that would be there if the action isn't cancelled
      Returns:
      If the action has been cancelled
    • addParent

      void addParent(@NotNull @NotNull GUIParent parent)
      Adds a GUIParent to the set of GUIParents.
      Parameters:
      parent - The GUIParent to add
    • removeParent

      void removeParent(@NotNull @NotNull GUIParent parent)
      Removes a GUIParent from the set of GUIParents
      Parameters:
      parent - The GUIParent to remove
    • getParents

      Set<GUIParent> getParents()
      Gets all GUIParents.
      Returns:
      The GUIParents of this GUI
    • findAllWindows

      List<Window> findAllWindows()
      Finds all Windows that show this GUI.
      Returns:
      The list of Window that show this GUI
    • findAllCurrentViewers

      Set<org.bukkit.entity.Player> findAllCurrentViewers()
      Finds all Players that are currently seeing this Window.
      Returns:
      The list of Players that are currently seeing this Window
    • closeForAllViewers

      void closeForAllViewers()
      Closes the open Inventory for all viewers of Windows where this GUI is displayed. Does not actually call the Window.close(boolean) method, which will be indirectly invoked by the InventoryCloseEvent if the Window is set to close on that event.
    • playAnimation

      void playAnimation(@NotNull @NotNull Animation animation, @Nullable @Nullable Predicate<SlotElement> filter)
      Plays an Animation.
      Parameters:
      animation - The Animation to play.
      filter - The filter that selects which SlotElements should be animated.
    • cancelAnimation

      void cancelAnimation()
      Cancels the running Animation if there is one.
    • fill

      void fill(int start, int end, @Nullable @Nullable Item item, boolean replaceExisting)
      Fills the GUI with Items.
      Parameters:
      start - The start index of the fill (inclusive)
      end - The end index of the fill (exclusive)
      item - The Item that should be used or null to remove an existing item.
      replaceExisting - If existing Items should be replaced.
    • fill

      void fill(@Nullable @Nullable Item item, boolean replaceExisting)
      Fills the entire GUI with Items.
      Parameters:
      item - The Item that should be used or null to remove an existing item.
      replaceExisting - If existing Items should be replaced.
    • fillRow

      void fillRow(int row, @Nullable @Nullable Item item, boolean replaceExisting)
      Fills one row with a specific Item
      Parameters:
      row - The row
      item - The Item that should be used or null to remove an existing item.
      replaceExisting - If existing Items should be replaced.
    • fillColumn

      void fillColumn(int column, @Nullable @Nullable Item item, boolean replaceExisting)
      Fills one column with a specific Item
      Parameters:
      column - The column
      item - The Item that should be used or null to remove an existing item.
      replaceExisting - If existing Items should be replaced.
    • fillBorders

      void fillBorders(@Nullable @Nullable Item item, boolean replaceExisting)
      Fills the borders of this GUI with a specific Item
      Parameters:
      item - The Item that should be used or null to remove an existing item.
      replaceExisting - If existing Items should be replaced.
    • fillRectangle

      void fillRectangle(int x, int y, int width, int height, @Nullable @Nullable Item item, boolean replaceExisting)
      Fills a rectangle in this GUI with a specific Item
      Parameters:
      x - The x coordinate where the rectangle should start.
      y - The y coordinate where the rectangle should start.
      width - The width of the rectangle.
      height - The height of the rectangle
      item - The Item that should be used or null to remove an existing item.
      replaceExisting - If existing Items should be replaced.
    • fillRectangle

      void fillRectangle(int x, int y, @NotNull @NotNull GUI gui, boolean replaceExisting)
      Fills a rectangle of another GUI in this GUI.
      Parameters:
      x - The x coordinate where the rectangle should start
      y - The y coordinate where the rectangle should start
      gui - The GUI to be put into this GUI
      replaceExisting - If existing SlotElements should be replaced.
    • fillRectangle

      void fillRectangle(int x, int y, int width, @NotNull @NotNull VirtualInventory virtualInventory, boolean replaceExisting)
      Fills a rectangle of a VirtualInventory in this GUI.
      Parameters:
      x - The x coordinate where the rectangle should start
      y - The y coordinate where the rectangle should start
      width - The line length of the rectangle. (VirtualInventory does not define a width)
      virtualInventory - The VirtualInventory to be put into this GUI.
      replaceExisting - If existing SlotElements should be replaced.
    • fillRectangle

      void fillRectangle(int x, int y, int width, @NotNull @NotNull VirtualInventory virtualInventory, @Nullable @Nullable ItemProvider background, boolean replaceExisting)
      Fills a rectangle of a VirtualInventory in this GUI.
      Parameters:
      x - The x coordinate where the rectangle should start
      y - The y coordinate where the rectangle should start
      width - The line length of the rectangle. (VirtualInventory does not define a width)
      virtualInventory - The VirtualInventory to be put into this GUI.
      background - The ItemProvider for empty slots of the VirtualInventory
      replaceExisting - If existing SlotElements should be replaced.