Class AbstractGui

java.lang.Object
xyz.xenondevs.invui.gui.AbstractGui
All Implemented Interfaces:
Gui, GuiParent
Direct Known Subclasses:
AbstractPagedGui, AbstractScrollGui, AbstractTabGui

public abstract class AbstractGui extends Object implements Gui, GuiParent
The abstract base class of all Gui implementations.

Only in very rare circumstances should this class be used directly. Instead, use the static factory and builder functions in the Gui interfaces, such as Gui.normal().

  • Constructor Details

    • AbstractGui

      public AbstractGui(int width, int height)
      Creates a new AbstractGui with the specified width and height.
      Parameters:
      width - The width of the Gui
      height - The height of the Gui
  • Method Details

    • handleClick

      public void handleClick(int slotNumber, org.bukkit.entity.Player player, org.bukkit.event.inventory.ClickType clickType, org.bukkit.event.inventory.InventoryClickEvent event)
      Handles a click on a slot in the AbstractGui.
      Parameters:
      slotNumber - The slot number that was clicked
      player - The player that clicked
      clickType - The type of the click
      event - The InventoryClickEvent that was triggered
    • handleInvSlotElementClick

      protected void handleInvSlotElementClick(SlotElement.InventorySlotElement element, org.bukkit.event.inventory.InventoryClickEvent event)
      Handles a click on an SlotElement.InventorySlotElement.
      Parameters:
      element - The SlotElement.InventorySlotElement that was clicked
      event - The InventoryClickEvent that was triggered
    • handleInvLeftClick

      protected void handleInvLeftClick(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked, org.bukkit.inventory.ItemStack cursor)
      Handles a left click on an SlotElement.InventorySlotElement.
      Parameters:
      event - The InventoryClickEvent that was triggered
      inventory - The Inventory that was clicked
      slot - The slot that was clicked
      player - The Player that clicked
      clicked - The ItemStack that was clicked
      cursor - The ItemStack that is on the cursor
    • handleInvRightClick

      protected void handleInvRightClick(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked, org.bukkit.inventory.ItemStack cursor)
      Handles a right click on an SlotElement.InventorySlotElement.
      Parameters:
      event - The InventoryClickEvent that was triggered
      inventory - The Inventory that was clicked
      slot - The slot that was clicked
      player - The Player that clicked
      clicked - The ItemStack that was clicked
      cursor - The ItemStack that is on the cursor
    • handleInvItemShift

      protected void handleInvItemShift(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked)
      Handles a shift click on an SlotElement.InventorySlotElement.
      Parameters:
      event - The InventoryClickEvent that was triggered
      inventory - The Inventory that was clicked
      slot - The slot that was clicked
      player - The Player that clicked
      clicked - The ItemStack that was clicked
    • handleInvNumberKey

      protected void handleInvNumberKey(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked)
      Handles a number key press on an SlotElement.InventorySlotElement.
      Parameters:
      event - The InventoryClickEvent that was triggered
      inventory - The Inventory that was clicked
      slot - The slot that was clicked
      player - The Player that clicked
      clicked - The ItemStack that was clicked
    • handleInvOffHandKey

      protected void handleInvOffHandKey(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked)
      Handles an off-hand key press on an SlotElement.InventorySlotElement.
      Parameters:
      event - The InventoryClickEvent that was triggered
      inventory - The Inventory that was clicked
      slot - The slot that was clicked
      player - The Player that clicked
      clicked - The ItemStack that was clicked
    • handleInvDrop

      protected void handleInvDrop(boolean ctrl, org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked)
      Handles dropping items from a slot in an SlotElement.InventorySlotElement.
      Parameters:
      ctrl - Whether the player pressed the control key
      event - The InventoryClickEvent that was triggered
      inventory - The Inventory that was clicked
      slot - The slot that was clicked
      player - The Player that clicked
      clicked - The ItemStack that was clicked
    • handleInvDoubleClick

      protected void handleInvDoubleClick(org.bukkit.event.inventory.InventoryClickEvent event, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack cursor)
      Handles a double click on an SlotElement.InventorySlotElement.
      Parameters:
      event - The InventoryClickEvent that was triggered
      player - The Player that clicked
      cursor - The ItemStack that is on the cursor
    • handleInvMiddleClick

      protected void handleInvMiddleClick(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot)
      Handles a middle click on an SlotElement.InventorySlotElement.
      Parameters:
      event - The InventoryClickEvent that was triggered
      inventory - The Inventory that was clicked
      slot - The slot that was clicked
    • handleItemDrag

      public boolean handleItemDrag(UpdateReason updateReason, int slot, org.bukkit.inventory.ItemStack oldStack, org.bukkit.inventory.ItemStack newStack)
      Handles an item drag on a single slot of this AbstractGui.
      Parameters:
      updateReason - The UpdateReason to be used in case the affected slot is an Inventory
      slot - The slot that was dragged
      oldStack - The old ItemStack in the slot
      newStack - The new ItemStack in the slot
      Returns:
      Whether the drag was successful.
    • handleItemShift

      public void handleItemShift(org.bukkit.event.inventory.InventoryClickEvent event)
      Handles an item shift click from outside this AbstractGui into it.
      Parameters:
      event - The InventoryClickEvent that was triggered
    • putIntoFirstInventory

      protected int putIntoFirstInventory(UpdateReason updateReason, org.bukkit.inventory.ItemStack itemStack, Inventory... ignored)
      Puts an ItemStack into the first Inventory that accepts it.
      Parameters:
      updateReason - The UpdateReason to be used for Inventory.addItem(UpdateReason, ItemStack)
      itemStack - The ItemStack to put into the first Inventory
      ignored - The Inventories to ignore
      Returns:
      The amount of items that could not be put into any Inventory
    • getAllInventorySlots

      public Map<Inventory,Set<Integer>> getAllInventorySlots(Inventory... ignored)
      Gets all Inventories and their slots that are used in this AbstractGui.
      Parameters:
      ignored - The Inventories to ignore
      Returns:
      A map of all Inventories and their slots that are visible.
    • getAllInventories

      public Collection<Inventory> getAllInventories(Inventory... ignored)
      Gets all Inventories that are used in this AbstractGui. If Gui.isIgnoreObscuredInventorySlots(), is true, ObscuredInventories will be used to only show the visible slots. Otherwise, this method will just return all Inventories, regardless of which of their slots are actually used.
      Parameters:
      ignored - The Inventories to ignore
      Returns:
      A collection of all Inventories used in this AbstractGui.
    • handleSlotElementUpdate

      public void handleSlotElementUpdate(Gui child, int slotIndex)
      Description copied from interface: GuiParent
      Called by the child Gui to report an update of a SlotElement.
      Specified by:
      handleSlotElementUpdate in interface GuiParent
      Parameters:
      child - The child Gui whose SlotElement has changed
      slotIndex - The slot index of the changed SlotElement in the child Gui
    • addParent

      public void addParent(@NotNull @NotNull GuiParent parent)
      Adds a GuiParent to this AbstractGui.
      Parameters:
      parent - The GuiParent to add
    • removeParent

      public void removeParent(@NotNull @NotNull GuiParent parent)
      Removes a GuiParent from this AbstractGui.
      Parameters:
      parent - The GuiParent to remove
    • getParents

      public Set<GuiParent> getParents()
      Gets all GuiParents of this AbstractGui.
      Returns:
      A set of all GuiParents
    • findAllWindows

      @NotNull public @NotNull List<@NotNull Window> findAllWindows()
      Description copied from interface: Gui
      Finds all Windows that show this Gui.
      Specified by:
      findAllWindows in interface Gui
      Returns:
      The list of Window that show this Gui
    • findAllCurrentViewers

      @NotNull public @NotNull Set<@NotNull org.bukkit.entity.Player> findAllCurrentViewers()
      Description copied from interface: Gui
      Finds all Players that are currently seeing this Window.
      Specified by:
      findAllCurrentViewers in interface Gui
      Returns:
      The list of Players that are currently seeing this Window
    • closeForAllViewers

      public void closeForAllViewers()
      Description copied from interface: Gui
      Closes the open Inventory for all viewers of Windows where this Gui is displayed.

      If the Windows are not marked as "retain", they will be removed from the WindowManager automatically.

      Specified by:
      closeForAllViewers in interface Gui
    • playAnimation

      public void playAnimation(@NotNull @NotNull Animation animation, @Nullable @Nullable Predicate<@NotNull SlotElement> filter)
      Description copied from interface: Gui
      Plays an Animation.
      Specified by:
      playAnimation in interface Gui
      Parameters:
      animation - The Animation to play.
      filter - The filter that selects which SlotElements should be animated.
    • cancelAnimation

      public void cancelAnimation()
      Description copied from interface: Gui
      Cancels the running Animation if there is one.
      Specified by:
      cancelAnimation in interface Gui
    • updateControlItems

      public void updateControlItems()
      Finds an updates all ControlItems in this AbstractGui.
    • setSlotElement

      public void setSlotElement(int index, SlotElement slotElement)
      Description copied from interface: Gui
      Sets the SlotElement on these coordinates. If you need to set an Item, please use Gui.setItem(int, Item) instead.
      Specified by:
      setSlotElement in interface Gui
      Parameters:
      index - The slot index
      slotElement - The SlotElement to be placed there.
    • addSlotElements

      public void addSlotElements(@NotNull @NotNull SlotElement... slotElements)
      Description copied from interface: Gui
      Adds SlotElements to the Gui.
      Specified by:
      addSlotElements in interface Gui
      Parameters:
      slotElements - The SlotElements to add.
    • getSlotElement

      @Nullable public @Nullable SlotElement getSlotElement(int index)
      Description copied from interface: Gui
      Gets the SlotElement placed on that slot.
      Specified by:
      getSlotElement in interface Gui
      Parameters:
      index - The slot index
      Returns:
      The SlotElement placed on that slot
    • hasSlotElement

      public boolean hasSlotElement(int index)
      Description copied from interface: Gui
      Gets if there is a SlotElement placed on that slot.
      Specified by:
      hasSlotElement in interface Gui
      Parameters:
      index - The slot index
      Returns:
      If there is a SlotElement placed there
    • getSlotElements

      @Nullable public @Nullable SlotElement @NotNull [] getSlotElements()
      Description copied from interface: Gui
      Gets all SlotElements of this Gui in an Array.
      Specified by:
      getSlotElements in interface Gui
      Returns:
      All SlotElements of this Gui
    • setItem

      public void setItem(int index, @Nullable @Nullable Item item)
      Description copied from interface: Gui
      Sets the Item on that slot
      Specified by:
      setItem in interface Gui
      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.
    • addItems

      public void addItems(@NotNull @NotNull Item... items)
      Description copied from interface: Gui
      Adds Items to the gui.
      Specified by:
      addItems in interface Gui
      Parameters:
      items - The Items that should be added to the gui
    • getItem

      @Nullable public @Nullable Item getItem(int index)
      Description copied from interface: Gui
      Gets the Item placed on that slot.
      Specified by:
      getItem in interface Gui
      Parameters:
      index - The slot index
      Returns:
      The Item which is placed on that slot or null if there isn't one
    • getBackground

      @Nullable public @Nullable ItemProvider getBackground()
      Description copied from interface: Gui
      Gets the ItemProvider that will be used if nothing else is placed on a slot.
      Specified by:
      getBackground in interface Gui
      Returns:
      The ItemProvider
    • setBackground

      public void setBackground(ItemProvider itemProvider)
      Description copied from interface: Gui
      Sets the ItemProvider that will be used if nothing else is placed on a slot.
      Specified by:
      setBackground in interface Gui
      Parameters:
      itemProvider - The ItemProvider
    • remove

      public void remove(int index)
      Description copied from interface: Gui
      Remove the Item which are placed on these slots.
      Specified by:
      remove in interface Gui
      Parameters:
      index - The slot index of the Items that should be removed
    • applyStructure

      public void applyStructure(@NotNull @NotNull Structure structure)
      Description copied from interface: Gui
      Applies the given Structure to the Gui.
      Specified by:
      applyStructure in interface Gui
      Parameters:
      structure - The structure
    • getSize

      public int getSize()
      Description copied from interface: Gui
      Gets the size of the Gui.
      Specified by:
      getSize in interface Gui
      Returns:
      The size of the gui.
    • setFrozen

      public void setFrozen(boolean frozen)
      Description copied from interface: Gui
      Freezes or unfreezes the Gui. A frozen Gui will not allow any clicks.
      Specified by:
      setFrozen in interface Gui
      Parameters:
      frozen - If the Gui should be frozen or not.
    • isFrozen

      public boolean isFrozen()
      Description copied from interface: Gui
      Gets if the Gui is frozen.
      Specified by:
      isFrozen in interface Gui
      Returns:
      If the Gui is frozen.
    • setIgnoreObscuredInventorySlots

      public void setIgnoreObscuredInventorySlots(boolean ignoreObscuredInventorySlots)
      Description copied from interface: Gui
      Configures whether it is possible to shift-click items into and cursor collect items from all Inventory slots of partially obscured embedded Inventories.

      Defaults to true.

      Specified by:
      setIgnoreObscuredInventorySlots in interface Gui
      Parameters:
      ignoreObscuredInventorySlots - Whether obscured Inventory slots should be ignored when shift-clicking and collecting to the cursor.
    • isIgnoreObscuredInventorySlots

      public boolean isIgnoreObscuredInventorySlots()
      Description copied from interface: Gui
      Gets whether it is possible to shift-click items into and cursor collect items from all Inventory slots of partially obscured embedded Inventories.
      Specified by:
      isIgnoreObscuredInventorySlots in interface Gui
      Returns:
      Whether obscured Inventory slots are ignored when shift-clicking and collecting to the cursor.
    • setSlotElement

      public void setSlotElement(int x, int y, SlotElement slotElement)
      Description copied from interface: Gui
      Sets the SlotElement on these coordinates. If you need to set an Item, please use Gui.setItem(int, int, Item) instead.
      Specified by:
      setSlotElement in interface Gui
      Parameters:
      x - The x coordinate
      y - The y coordinate
      slotElement - The SlotElement to be placed there.
    • getSlotElement

      @Nullable public @Nullable SlotElement getSlotElement(int x, int y)
      Description copied from interface: Gui
      Gets the SlotElement on these coordinates.
      Specified by:
      getSlotElement in interface Gui
      Parameters:
      x - The x coordinate
      y - The y coordinate
      Returns:
      The SlotElement placed there
    • hasSlotElement

      public boolean hasSlotElement(int x, int y)
      Description copied from interface: Gui
      Gets if there is a SlotElement on these coordinates.
      Specified by:
      hasSlotElement in interface Gui
      Parameters:
      x - The x coordinate
      y - The y coordinate
      Returns:
      If there is a SlotElement placed there
    • setItem

      public void setItem(int x, int y, @Nullable @Nullable Item item)
      Description copied from interface: Gui
      Sets the Item on these coordinates.
      Specified by:
      setItem in interface Gui
      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.
    • getItem

      @Nullable public @Nullable Item getItem(int x, int y)
      Description copied from interface: Gui
      Gets the Item on these coordinates.
      Specified by:
      getItem in interface Gui
      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
    • remove

      public void remove(int x, int y)
      Description copied from interface: Gui
      Removes an Item by its coordinates.
      Specified by:
      remove in interface Gui
      Parameters:
      x - The x coordinate
      y - The y coordinate
    • getWidth

      public int getWidth()
      Description copied from interface: Gui
      Gets the width of the Gui
      Specified by:
      getWidth in interface Gui
      Returns:
      The width of the Gui
    • getHeight

      public int getHeight()
      Description copied from interface: Gui
      Gets the height of the Gui
      Specified by:
      getHeight in interface Gui
      Returns:
      The height of the Gui
    • fill

      public void fill(int start, int end, @Nullable @Nullable Item item, boolean replaceExisting)
      Description copied from interface: Gui
      Fills the Gui with Items.
      Specified by:
      fill in interface Gui
      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

      public void fill(@Nullable @Nullable Item item, boolean replaceExisting)
      Description copied from interface: Gui
      Fills the entire Gui with Items.
      Specified by:
      fill in interface Gui
      Parameters:
      item - The Item that should be used or null to remove an existing item.
      replaceExisting - If existing Items should be replaced.
    • fillRow

      public void fillRow(int row, @Nullable @Nullable Item item, boolean replaceExisting)
      Description copied from interface: Gui
      Fills one row with a specific Item
      Specified by:
      fillRow in interface Gui
      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

      public void fillColumn(int column, @Nullable @Nullable Item item, boolean replaceExisting)
      Description copied from interface: Gui
      Fills one column with a specific Item
      Specified by:
      fillColumn in interface Gui
      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

      public void fillBorders(@Nullable @Nullable Item item, boolean replaceExisting)
      Description copied from interface: Gui
      Fills the borders of this Gui with a specific Item
      Specified by:
      fillBorders in interface Gui
      Parameters:
      item - The Item that should be used or null to remove an existing item.
      replaceExisting - If existing Items should be replaced.
    • fillRectangle

      public void fillRectangle(int x, int y, int width, int height, @Nullable @Nullable Item item, boolean replaceExisting)
      Description copied from interface: Gui
      Fills a rectangle in this Gui with a specific Item
      Specified by:
      fillRectangle in interface Gui
      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

      public void fillRectangle(int x, int y, @NotNull @NotNull Gui gui, boolean replaceExisting)
      Description copied from interface: Gui
      Fills a rectangle with another Gui in this Gui.
      Specified by:
      fillRectangle in interface 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

      public void fillRectangle(int x, int y, int width, @NotNull @NotNull Inventory inventory, boolean replaceExisting)
      Description copied from interface: Gui
      Fills a rectangle with a Inventory in this Gui.
      Specified by:
      fillRectangle in interface 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.
      inventory - The Inventory to be put into this Gui.
      replaceExisting - If existing SlotElements should be replaced.
    • fillRectangle

      public void fillRectangle(int x, int y, int width, @NotNull @NotNull Inventory inventory, @Nullable @Nullable ItemProvider background, boolean replaceExisting)
      Description copied from interface: Gui
      Fills a rectangle with a Inventory in this Gui.
      Specified by:
      fillRectangle in interface 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.
      inventory - The Inventory to be put into this Gui.
      background - The ItemProvider for empty slots of the Inventory
      replaceExisting - If existing SlotElements should be replaced.