Package dev.triumphteam.gui.guis
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 Summary
Constructors Constructor Description BaseGui(int rows, @NotNull java.lang.String title)
Deprecated.In favor ofBaseGui(int, Component, Set)
.BaseGui(int rows, @NotNull net.kyori.adventure.text.Component title, @NotNull java.util.Set<InteractionModifier> interactionModifiers)
The main constructor, usingComponent
.BaseGui(@NotNull GuiType guiType, @NotNull java.lang.String title)
Deprecated.In favor ofBaseGui(GuiType, Component, Set)
.BaseGui(@NotNull GuiType guiType, @NotNull net.kyori.adventure.text.Component title, @NotNull java.util.Set<InteractionModifier> interactionModifiers)
Alternative constructor that takesGuiType
instead of rows number. -
Method Summary
Modifier and Type Method Description void
addItem(@NotNull GuiItem... items)
AddsGuiItem
s to the GUI without specific slot.void
addSlotAction(int row, int col, @Nullable GuiAction<org.bukkit.event.inventory.InventoryClickEvent> slotAction)
Alternative method foraddSlotAction(int, GuiAction)
to add aGuiAction
to a specific slot using ROWS and COLUMNS instead of slots.void
addSlotAction(int slot, @Nullable GuiAction<org.bukkit.event.inventory.InventoryClickEvent> slotAction)
Adds aGuiAction
for when clicking on a specific slot.boolean
canPlaceItems()
Check if item placement is allowed inside this GUI.boolean
canSwapItems()
Check if item swap is allowed inside this GUI.boolean
canTakeItems()
Check if item retrieval is allowed inside this GUI.void
close(@NotNull org.bukkit.entity.HumanEntity player)
Closes the GUI with a2 tick
delay (to prevent items from being taken from theInventory
).void
close(@NotNull org.bukkit.entity.HumanEntity player, boolean runCloseAction)
Closes the GUI with a2 tick
delay (to prevent items from being taken from theInventory
).BaseGui
disableAllInteractions()
Disable all the modifications of the GUI, making it immutable by player interaction.BaseGui
disableItemPlace()
Disable item placement inside the GUI.BaseGui
disableItemSwap()
Disable item swap inside the GUI.BaseGui
disableItemTake()
Disable item retrieval inside the GUI.BaseGui
enableAllInteractions()
Enable all modifications of the GUI, making it completely mutable by player interaction.BaseGui
enableItemPlace()
Allows item placement inside the GUI.BaseGui
enableItemSwap()
Allows item swap inside the GUI.BaseGui
enableItemTake()
Allow items to be taken from the GUI.@NotNull GuiFiller
getFiller()
Gets theGuiFiller
that it's used for filling up the GUI in specific ways.@Nullable GuiItem
getGuiItem(int slot)
Gets a specificGuiItem
on the slot.java.util.Map<java.lang.Integer,GuiItem>
getGuiItems()
Gets an immutableMap
with all the GUI items.@NotNull org.bukkit.inventory.Inventory
getInventory()
Gets the mainInventory
of this GUI.int
getRows()
Gets the amount ofrows
.GuiType
guiType()
Gets theGuiType
in use.boolean
isUpdating()
Checks whether or not the GUI is updating.void
open(@NotNull org.bukkit.entity.HumanEntity player)
Opens the GUI for aHumanEntity
.void
removeItem(int slot)
Removes theGuiItem
in the specific slot.void
removeItem(int row, int col)
AlternativeremoveItem(int)
with cols and rows.void
setCloseGuiAction(@Nullable GuiAction<org.bukkit.event.inventory.InventoryCloseEvent> closeGuiAction)
Sets theGuiAction
to run once the inventory is closed.void
setDefaultClickAction(@Nullable GuiAction<org.bukkit.event.inventory.InventoryClickEvent> defaultClickAction)
Sets theGuiAction
of a default click on any item.void
setDefaultTopClickAction(@Nullable GuiAction<org.bukkit.event.inventory.InventoryClickEvent> defaultTopClickAction)
Sets theGuiAction
of a default click on any item on the top part of the GUI.void
setDragAction(@Nullable GuiAction<org.bukkit.event.inventory.InventoryDragEvent> dragAction)
Sets theGuiAction
of a default drag action.void
setInventory(@NotNull org.bukkit.inventory.Inventory inventory)
Sets the new inventory of the GUI.void
setItem(int row, int col, @NotNull GuiItem guiItem)
AlternativesetItem(int, GuiItem)
to set item that uses ROWS and COLUMNS instead of slots.void
setItem(int slot, @NotNull GuiItem guiItem)
Sets theGuiItem
to a specific slot on the GUI.void
setItem(@NotNull java.util.List<java.lang.Integer> slots, @NotNull GuiItem guiItem)
AlternativesetItem(int, GuiItem)
to set item that takes aList
of slots instead.void
setOpenGuiAction(@Nullable GuiAction<org.bukkit.event.inventory.InventoryOpenEvent> openGuiAction)
Sets theGuiAction
to run when the GUI opens.void
setOutsideClickAction(@Nullable GuiAction<org.bukkit.event.inventory.InventoryClickEvent> outsideClickAction)
Sets theGuiAction
to run when clicking on the outside of the inventory.void
setPlayerInventoryAction(@Nullable GuiAction<org.bukkit.event.inventory.InventoryClickEvent> playerInventoryAction)
void
setUpdating(boolean updating)
Sets the updating status of the GUI.void
update()
Updates the GUI for all theInventory
views.void
updateItem(int row, int col, @NotNull GuiItem item)
AlternativeupdateItem(int, GuiItem)
that takes ROWS and COLUMNS instead of slots.void
updateItem(int row, int col, @NotNull org.bukkit.inventory.ItemStack itemStack)
AlternativeupdateItem(int, ItemStack)
that takes ROWS and COLUMNS instead of slots.void
updateItem(int slot, @NotNull GuiItem item)
AlternativeupdateItem(int, ItemStack)
but creates a newGuiItem
.void
updateItem(int slot, @NotNull org.bukkit.inventory.ItemStack itemStack)
Updates the specified item in the GUI at runtime, without creating a newGuiItem
.BaseGui
updateTitle(@NotNull java.lang.String title)
Deprecated.Should useupdateTitle(Component)
instead.BaseGui
updateTitle(@NotNull net.kyori.adventure.text.Component title)
Updates the title of the 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, usingComponent
.- Parameters:
rows
- The amount of rows to use.title
- The GUI title usingComponent
.- 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 takesGuiType
instead of rows number.- Parameters:
guiType
- TheGuiType
to use.title
- The GUI title usingComponent
.- Since:
- 3.0.0
-
BaseGui
@Deprecated public BaseGui(int rows, @NotNull @NotNull java.lang.String title)Deprecated.In favor ofBaseGui(int, Component, Set)
.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.In favor ofBaseGui(GuiType, Component, Set)
.Alternative constructor that takesGuiType
instead of rows number.- Parameters:
guiType
- TheGuiType
to use.title
- The GUI title.
-
-
Method Details
-
setItem
Sets theGuiItem
to a specific slot on the GUI.- Parameters:
slot
- The GUI slot.guiItem
- TheGuiItem
to add to the slot.
-
removeItem
public void removeItem(int slot)Removes theGuiItem
in the specific slot.- Parameters:
slot
- The GUI slot.
-
removeItem
public void removeItem(int row, int col)AlternativeremoveItem(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)AlternativesetItem(int, GuiItem)
to set item that takes aList
of slots instead.- Parameters:
slots
- The slots in which the item should go.guiItem
- TheGuiItem
to add to the slots.
-
setItem
AlternativesetItem(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
- TheGuiItem
to add to the slot.
-
addItem
AddsGuiItem
s to the GUI without specific slot. It'll set the item to the next empty slot available.- Parameters:
items
- Varargs for specifying theGuiItem
s.
-
setDefaultClickAction
public void setDefaultClickAction(@Nullable @Nullable GuiAction<org.bukkit.event.inventory.InventoryClickEvent> defaultClickAction)Sets theGuiAction
of a default click on any item. SeeInventoryClickEvent
.- Parameters:
defaultClickAction
-GuiAction
to resolve when any item is clicked.
-
setDefaultTopClickAction
public void setDefaultTopClickAction(@Nullable @Nullable GuiAction<org.bukkit.event.inventory.InventoryClickEvent> defaultTopClickAction)Sets theGuiAction
of a default click on any item on the top part of the GUI. Top inventory being for example chests etc, instead of thePlayer
inventory. SeeInventoryClickEvent
.- 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 theGuiAction
to run when clicking on the outside of the inventory. SeeInventoryClickEvent
.- 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 theGuiAction
of a default drag action. SeeInventoryDragEvent
.- Parameters:
dragAction
-GuiAction
to resolve.
-
setCloseGuiAction
public void setCloseGuiAction(@Nullable @Nullable GuiAction<org.bukkit.event.inventory.InventoryCloseEvent> closeGuiAction)Sets theGuiAction
to run once the inventory is closed. SeeInventoryCloseEvent
.- Parameters:
closeGuiAction
-GuiAction
to resolve when the inventory is closed.
-
setOpenGuiAction
public void setOpenGuiAction(@Nullable @Nullable GuiAction<org.bukkit.event.inventory.InventoryOpenEvent> openGuiAction)Sets theGuiAction
to run when the GUI opens. SeeInventoryOpenEvent
.- 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 aGuiAction
for when clicking on a specific slot. SeeInventoryClickEvent
. -
addSlotAction
public void addSlotAction(int row, int col, @Nullable @Nullable GuiAction<org.bukkit.event.inventory.InventoryClickEvent> slotAction)Alternative method foraddSlotAction(int, GuiAction)
to add aGuiAction
to a specific slot using ROWS and COLUMNS instead of slots. SeeInventoryClickEvent
.- Parameters:
row
- The row of the slot.col
- The column of the slot.slotAction
-GuiAction
to resolve when clicking on the slot.
-
getGuiItem
Gets a specificGuiItem
on the slot.- Parameters:
slot
- The slot of the item.- Returns:
- The
GuiItem
on the introduced slot ornull
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 aHumanEntity
.- Parameters:
player
- TheHumanEntity
to open the GUI to.
-
close
public void close(@NotNull @NotNull org.bukkit.entity.HumanEntity player)Closes the GUI with a2 tick
delay (to prevent items from being taken from theInventory
).- Parameters:
player
- TheHumanEntity
to close the GUI to.
-
close
public void close(@NotNull @NotNull org.bukkit.entity.HumanEntity player, boolean runCloseAction)Closes the GUI with a2 tick
delay (to prevent items from being taken from theInventory
).- Parameters:
player
- TheHumanEntity
to close the GUI to.runCloseAction
- If should or not run the close action.
-
update
public void update()Updates the GUI for all theInventory
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 newGuiItem
.- Parameters:
slot
- The slot of the item to update.itemStack
- TheItemStack
to replace in the original one in theGuiItem
.
-
updateItem
public void updateItem(int row, int col, @NotNull @NotNull org.bukkit.inventory.ItemStack itemStack)AlternativeupdateItem(int, ItemStack)
that takes ROWS and COLUMNS instead of slots.- Parameters:
row
- The row of the slot.col
- The columns of the slot.itemStack
- TheItemStack
to replace in the original one in theGuiItem
.
-
updateItem
AlternativeupdateItem(int, ItemStack)
but creates a newGuiItem
.- Parameters:
slot
- The slot of the item to update.item
- TheGuiItem
to replace in the original.
-
updateItem
AlternativeupdateItem(int, GuiItem)
that takes ROWS and COLUMNS instead of slots.- Parameters:
row
- The row of the slot.col
- The columns of the slot.item
- TheGuiItem
to replace in the original.
-
updateTitle
Deprecated.Should useupdateTitle(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
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
Disable item placement inside the GUI.- Returns:
- The BaseGui.
- Since:
- 3.0.0.
-
disableItemTake
Disable item retrieval inside the GUI.- Returns:
- The BaseGui.
- Since:
- 3.0.0.
-
disableItemSwap
Disable item swap inside the GUI.- Returns:
- The BaseGui.
- Since:
- 3.0.0.
-
disableAllInteractions
Disable all the modifications of the GUI, making it immutable by player interaction.- Returns:
- The BaseGui.
- Since:
- 3.0.0.
-
enableItemPlace
Allows item placement inside the GUI.- Returns:
- The BaseGui.
- Since:
- 3.0.0.
-
enableItemTake
Allow items to be taken from the GUI.- Returns:
- The BaseGui.
- Since:
- 3.0.0.
-
enableItemSwap
Allows item swap inside the GUI.- Returns:
- The BaseGui.
- Since:
- 3.0.0.
-
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
Gets theGuiFiller
that it's used for filling up the GUI in specific ways.- Returns:
- The
GuiFiller
.
-
getGuiItems
Gets an immutableMap
with all the GUI items.- Returns:
- The
Map
with all theguiItems
.
-
getInventory
@NotNull public @NotNull org.bukkit.inventory.Inventory getInventory()Gets the mainInventory
of this GUI.- Specified by:
getInventory
in interfaceorg.bukkit.inventory.InventoryHolder
- Returns:
- Gets the
Inventory
from the holder.
-
getRows
public int getRows()Gets the amount ofrows
.- Returns:
- The
rows
of the GUI.
-
guiType
Gets theGuiType
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.
-