Class BaseGui

java.lang.Object
dev.triumphteam.gui.guis.BaseGui
All Implemented Interfaces:
org.bukkit.inventory.InventoryHolder
Direct Known Subclasses:
Gui, PaginatedGui, StorageGui

public abstract class BaseGui
extends java.lang.Object
implements org.bukkit.inventory.InventoryHolder
Base class that every GUI extends. Contains all the basics for the GUI to work. Main and simplest implementation of this is Gui.
  • Constructor Details

    • BaseGui

      public BaseGui​(int rows, @NotNull @NotNull net.kyori.adventure.text.Component title, @NotNull @NotNull java.util.Set<InteractionModifier> interactionModifiers)
      The main constructor, using Component.
      Parameters:
      rows - The amount of rows to use.
      title - The GUI title using Component.
      Since:
      3.0.0.
    • BaseGui

      public BaseGui​(@NotNull @NotNull GuiType guiType, @NotNull @NotNull net.kyori.adventure.text.Component title, @NotNull @NotNull java.util.Set<InteractionModifier> interactionModifiers)
      Alternative constructor that takes GuiType instead of rows number.
      Parameters:
      guiType - The GuiType to use.
      title - The GUI title using Component.
      Since:
      3.0.0
    • BaseGui

      @Deprecated public BaseGui​(int rows, @NotNull @NotNull java.lang.String title)
      Deprecated.
      Legacy constructor that takes rows and title.
      Parameters:
      rows - The amount of rows the GUI should have.
      title - The GUI title.
    • BaseGui

      @Deprecated public BaseGui​(@NotNull @NotNull GuiType guiType, @NotNull @NotNull java.lang.String title)
      Deprecated.
      Alternative constructor that takes GuiType instead of rows number.
      Parameters:
      guiType - The GuiType to use.
      title - The GUI title.
  • Method Details

    • setItem

      public void setItem​(int slot, @NotNull @NotNull GuiItem guiItem)
      Sets the GuiItem to a specific slot on the GUI.
      Parameters:
      slot - The GUI slot.
      guiItem - The GuiItem to add to the slot.
    • removeItem

      public void removeItem​(int slot)
      Removes the GuiItem in the specific slot.
      Parameters:
      slot - The GUI slot.
    • removeItem

      public void removeItem​(int row, int col)
      Alternative removeItem(int) with cols and rows.
      Parameters:
      row - The row.
      col - The column.
    • setItem

      public void setItem​(@NotNull @NotNull java.util.List<java.lang.Integer> slots, @NotNull @NotNull GuiItem guiItem)
      Alternative setItem(int, GuiItem) to set item that takes a List of slots instead.
      Parameters:
      slots - The slots in which the item should go.
      guiItem - The GuiItem to add to the slots.
    • setItem

      public void setItem​(int row, int col, @NotNull @NotNull GuiItem guiItem)
      Alternative setItem(int, GuiItem) to set item that uses ROWS and COLUMNS instead of slots.
      Parameters:
      row - The GUI row number.
      col - The GUI column number.
      guiItem - The GuiItem to add to the slot.
    • addItem

      public void addItem​(@NotNull @NotNull GuiItem... items)
      Adds GuiItems to the GUI without specific slot. It'll set the item to the next empty slot available.
      Parameters:
      items - Varargs for specifying the GuiItems.
    • setDefaultClickAction

      public void setDefaultClickAction​(@Nullable @Nullable GuiAction<org.bukkit.event.inventory.InventoryClickEvent> defaultClickAction)
      Sets the GuiAction of a default click on any item. See InventoryClickEvent.
      Parameters:
      defaultClickAction - GuiAction to resolve when any item is clicked.
    • setDefaultTopClickAction

      public void setDefaultTopClickAction​(@Nullable @Nullable GuiAction<org.bukkit.event.inventory.InventoryClickEvent> defaultTopClickAction)
      Sets the GuiAction of a default click on any item on the top part of the GUI. Top inventory being for example chests etc, instead of the Player inventory. See InventoryClickEvent.
      Parameters:
      defaultTopClickAction - GuiAction to resolve when clicking on the top inventory.
    • setPlayerInventoryAction

      public void setPlayerInventoryAction​(@Nullable @Nullable GuiAction<org.bukkit.event.inventory.InventoryClickEvent> playerInventoryAction)
    • setOutsideClickAction

      public void setOutsideClickAction​(@Nullable @Nullable GuiAction<org.bukkit.event.inventory.InventoryClickEvent> outsideClickAction)
      Sets the GuiAction to run when clicking on the outside of the inventory. See InventoryClickEvent.
      Parameters:
      outsideClickAction - GuiAction to resolve when clicking outside of the inventory.
    • setDragAction

      public void setDragAction​(@Nullable @Nullable GuiAction<org.bukkit.event.inventory.InventoryDragEvent> dragAction)
      Sets the GuiAction of a default drag action. See InventoryDragEvent.
      Parameters:
      dragAction - GuiAction to resolve.
    • setCloseGuiAction

      public void setCloseGuiAction​(@Nullable @Nullable GuiAction<org.bukkit.event.inventory.InventoryCloseEvent> closeGuiAction)
      Sets the GuiAction to run once the inventory is closed. See InventoryCloseEvent.
      Parameters:
      closeGuiAction - GuiAction to resolve when the inventory is closed.
    • setOpenGuiAction

      public void setOpenGuiAction​(@Nullable @Nullable GuiAction<org.bukkit.event.inventory.InventoryOpenEvent> openGuiAction)
      Sets the GuiAction to run when the GUI opens. See InventoryOpenEvent.
      Parameters:
      openGuiAction - GuiAction to resolve when opening the inventory.
    • addSlotAction

      public void addSlotAction​(int slot, @Nullable @Nullable GuiAction<org.bukkit.event.inventory.InventoryClickEvent> slotAction)
      Adds a GuiAction for when clicking on a specific slot. See InventoryClickEvent.
      Parameters:
      slot - The slot that will trigger the GuiAction.
      slotAction - GuiAction to resolve when clicking on specific slots.
    • addSlotAction

      public void addSlotAction​(int row, int col, @Nullable @Nullable GuiAction<org.bukkit.event.inventory.InventoryClickEvent> slotAction)
      Alternative method for addSlotAction(int, GuiAction) to add a GuiAction to a specific slot using ROWS and COLUMNS instead of slots. See InventoryClickEvent.
      Parameters:
      row - The row of the slot.
      col - The column of the slot.
      slotAction - GuiAction to resolve when clicking on the slot.
    • getGuiItem

      @Nullable public @Nullable GuiItem getGuiItem​(int slot)
      Gets a specific GuiItem on the slot.
      Parameters:
      slot - The slot of the item.
      Returns:
      The GuiItem on the introduced slot or null if doesn't exist.
    • isUpdating

      public boolean isUpdating()
      Checks whether or not the GUI is updating.
      Returns:
      Whether the GUI is updating or not.
    • setUpdating

      public void setUpdating​(boolean updating)
      Sets the updating status of the GUI.
      Parameters:
      updating - Sets the GUI to the updating status.
    • open

      public void open​(@NotNull @NotNull org.bukkit.entity.HumanEntity player)
      Opens the GUI for a HumanEntity.
      Parameters:
      player - The HumanEntity to open the GUI to.
    • close

      public void close​(@NotNull @NotNull org.bukkit.entity.HumanEntity player)
      Closes the GUI with a 2 tick delay (to prevent items from being taken from the Inventory).
      Parameters:
      player - The HumanEntity to close the GUI to.
    • close

      public void close​(@NotNull @NotNull org.bukkit.entity.HumanEntity player, boolean runCloseAction)
      Closes the GUI with a 2 tick delay (to prevent items from being taken from the Inventory).
      Parameters:
      player - The HumanEntity to close the GUI to.
      runCloseAction - If should or not run the close action.
    • update

      public void update()
      Updates the GUI for all the Inventory views.
    • updateItem

      public void updateItem​(int slot, @NotNull @NotNull org.bukkit.inventory.ItemStack itemStack)
      Updates the specified item in the GUI at runtime, without creating a new GuiItem.
      Parameters:
      slot - The slot of the item to update.
      itemStack - The ItemStack to replace in the original one in the GuiItem.
    • updateItem

      public void updateItem​(int row, int col, @NotNull @NotNull org.bukkit.inventory.ItemStack itemStack)
      Alternative updateItem(int, ItemStack) that takes ROWS and COLUMNS instead of slots.
      Parameters:
      row - The row of the slot.
      col - The columns of the slot.
      itemStack - The ItemStack to replace in the original one in the GuiItem.
    • updateItem

      public void updateItem​(int slot, @NotNull @NotNull GuiItem item)
      Alternative updateItem(int, ItemStack) but creates a new GuiItem.
      Parameters:
      slot - The slot of the item to update.
      item - The GuiItem to replace in the original.
    • updateItem

      public void updateItem​(int row, int col, @NotNull @NotNull GuiItem item)
      Alternative updateItem(int, GuiItem) that takes ROWS and COLUMNS instead of slots.
      Parameters:
      row - The row of the slot.
      col - The columns of the slot.
      item - The GuiItem to replace in the original.
    • updateTitle

      @Deprecated public BaseGui updateTitle​(@NotNull @NotNull java.lang.String title)
      Deprecated.
      Should use updateTitle(Component) instead.
      Updates the title of the GUI. This method may cause LAG if used on a loop.
      Parameters:
      title - The title to set.
      Returns:
      The GUI for easier use when declaring, works like a builder.
    • updateTitle

      public BaseGui updateTitle​(@NotNull @NotNull net.kyori.adventure.text.Component title)
      Updates the title of the GUI. I do not recommend using this too often.
      Parameters:
      title - The title to set.
      Returns:
      The GUI for easier use when declaring, works like a builder.
    • disableItemPlace

      @Contract(" -> this") public BaseGui disableItemPlace()
      Disable item placement inside the GUI.
      Returns:
      The BaseGui.
      Since:
      3.0.0.
    • disableItemTake

      @Contract(" -> this") public BaseGui disableItemTake()
      Disable item retrieval inside the GUI.
      Returns:
      The BaseGui.
      Since:
      3.0.0.
    • disableItemSwap

      @Contract(" -> this") public BaseGui disableItemSwap()
      Disable item swap inside the GUI.
      Returns:
      The BaseGui.
      Since:
      3.0.0.
    • disableAllInteractions

      @Contract(" -> this") public BaseGui disableAllInteractions()
      Disable all the modifications of the GUI, making it immutable by player interaction.
      Returns:
      The BaseGui.
      Since:
      3.0.0.
    • enableItemPlace

      @Contract(" -> this") public BaseGui enableItemPlace()
      Allows item placement inside the GUI.
      Returns:
      The BaseGui.
      Since:
      3.0.0.
    • enableItemTake

      @Contract(" -> this") public BaseGui enableItemTake()
      Allow items to be taken from the GUI.
      Returns:
      The BaseGui.
      Since:
      3.0.0.
    • enableItemSwap

      @Contract(" -> this") public BaseGui enableItemSwap()
      Allows item swap inside the GUI.
      Returns:
      The BaseGui.
      Since:
      3.0.0.
    • enableAllInteractions

      @Contract(" -> this") public BaseGui enableAllInteractions()
      Enable all modifications of the GUI, making it completely mutable by player interaction.
      Returns:
      The BaseGui.
      Since:
      3.0.0.
    • canPlaceItems

      public boolean canPlaceItems()
      Check if item placement is allowed inside this GUI.
      Returns:
      True if item placement is allowed for this GUI.
      Since:
      3.0.0.
    • canTakeItems

      public boolean canTakeItems()
      Check if item retrieval is allowed inside this GUI.
      Returns:
      True if item retrieval is allowed inside this GUI.
      Since:
      3.0.0.
    • canSwapItems

      public boolean canSwapItems()
      Check if item swap is allowed inside this GUI.
      Returns:
      True if item swap is allowed for this GUI.
      Since:
      3.0.0.
    • getFiller

      @NotNull public @NotNull GuiFiller getFiller()
      Gets the GuiFiller that it's used for filling up the GUI in specific ways.
      Returns:
      The GuiFiller.
    • getGuiItems

      public java.util.Map<java.lang.Integer,​GuiItem> getGuiItems()
      Gets an immutable Map with all the GUI items.
      Returns:
      The Map with all the guiItems.
    • getInventory

      @NotNull public @NotNull org.bukkit.inventory.Inventory getInventory()
      Gets the main Inventory of this GUI.
      Specified by:
      getInventory in interface org.bukkit.inventory.InventoryHolder
      Returns:
      Gets the Inventory from the holder.
    • getRows

      public int getRows()
      Gets the amount of rows.
      Returns:
      The rows of the GUI.
    • guiType

      public GuiType guiType()
      Gets the GuiType in use.
      Returns:
      The GuiType.
    • setInventory

      public void setInventory​(@NotNull @NotNull org.bukkit.inventory.Inventory inventory)
      Sets the new inventory of the GUI.
      Parameters:
      inventory - The new inventory.