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 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 String title, @NotNull @NotNull Set<InteractionModifier> interactionModifiers)
      The main constructor, using String.
      Parameters:
      rows - The amount of rows to use.
      title - The GUI title using String.
      interactionModifiers - Modifiers to select which interactions are allowed.
      Since:
      3.0.0.
    • BaseGui

      public BaseGui(@NotNull @NotNull GuiType guiType, @NotNull @NotNull String title, @NotNull @NotNull Set<InteractionModifier> interactionModifiers)
      Alternative constructor that takes GuiType instead of rows number.
      Parameters:
      guiType - The GuiType to use.
      title - The GUI title using String.
      interactionModifiers - Modifiers to select which interactions are allowed.
      Since:
      3.0.0
    • BaseGui

      @Deprecated public BaseGui(int rows, @NotNull @NotNull 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 String title)
      Deprecated.
      Alternative constructor that takes GuiType instead of rows number.
      Parameters:
      guiType - The GuiType to use.
      title - The GUI title.
  • Method Details

    • getTitle

      @NotNull @Deprecated public @NotNull String getTitle()
      Deprecated.
      Gets the GUI's title as string.
      Returns:
      The GUI's title.
    • title

      @NotNull public @NotNull net.kyori.adventure.text.Component title()
      Gets the GUI title as a Component.
      Returns:
      The GUI title Component.
    • 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(@NotNull @NotNull GuiItem item)
      Removes the given GuiItem from the GUI.
      Parameters:
      item - The item to remove.
    • removeItem

      public void removeItem(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Removes the given ItemStack from the GUI.
      Parameters:
      item - The item to remove.
    • 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 List<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.
    • addItem

      public void addItem(boolean expandIfFull, @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.
      expandIfFull - If true, expands the gui if it is full and there are more items to be added
    • setDefaultClickAction

      public void setDefaultClickAction(@Nullable @Nullable GuiAction<@NotNull 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<@NotNull 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<@NotNull org.bukkit.event.inventory.InventoryClickEvent> playerInventoryAction)
    • setOutsideClickAction

      public void setOutsideClickAction(@Nullable @Nullable GuiAction<@NotNull 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<@NotNull 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<@NotNull 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<@NotNull 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<@NotNull 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<@NotNull 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.
    • updateTitle

      @Contract("_ -> this") @NotNull public @NotNull BaseGui updateTitle(@NotNull @NotNull String title)
      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.
    • 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.
    • disableItemPlace

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

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

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

      @NotNull @Contract(" -> this") public @NotNull BaseGui disableItemDrop()
      Disable item drop inside the GUI
      Returns:
      The BaseGui
      Since:
      3.0.3.
    • disableOtherActions

      @NotNull @Contract(" -> this") public @NotNull BaseGui disableOtherActions()
      Disable other GUI actions This option pretty much disables creating a clone stack of the item
      Returns:
      The BaseGui
      Since:
      3.0.4
    • disableAllInteractions

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

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

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

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

      @NotNull @Contract(" -> this") public @NotNull BaseGui enableItemDrop()
      Allows item drop inside the GUI
      Returns:
      The BaseGui
      Since:
      3.0.3
    • enableOtherActions

      @NotNull @Contract(" -> this") public @NotNull BaseGui enableOtherActions()
      Enable other GUI actions This option pretty much enables creating a clone stack of the item
      Returns:
      The BaseGui
      Since:
      3.0.4
    • enableAllInteractions

      @NotNull @Contract(" -> this") public @NotNull 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.
    • canDropItems

      public boolean canDropItems()
      Check if item drop is allowed inside this GUI
      Returns:
      True if item drop is allowed for this GUI
      Since:
      3.0.3
    • allowsOtherActions

      public boolean allowsOtherActions()
      Check if any other actions are allowed in this GUI
      Returns:
      True if other actions are allowed
      Since:
      3.0.4
    • 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

      @NotNull public @NotNull Map<@NotNull Integer,@NotNull 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

      @NotNull public @NotNull 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.