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
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
ConstructorsConstructorDescriptionDeprecated.BaseGui(int rows, @NotNull String title, @NotNull Set<InteractionModifier> interactionModifiers) The main constructor, usingString.Deprecated.In favor ofBaseGui(GuiType, String, Set).BaseGui(@NotNull GuiType guiType, @NotNull String title, @NotNull Set<InteractionModifier> interactionModifiers) Alternative constructor that takesGuiTypeinstead of rows number. -
Method Summary
Modifier and TypeMethodDescriptionvoidAddsGuiItems to the GUI without specific slot.voidAddsGuiItems to the GUI without specific slot.voidaddSlotAction(int row, int col, @Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> slotAction) Alternative method foraddSlotAction(int, GuiAction)to add aGuiActionto a specific slot using ROWS and COLUMNS instead of slots.voidaddSlotAction(int slot, @Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> slotAction) Adds aGuiActionfor when clicking on a specific slot.booleanbooleanCheck if any other actions are allowed in this GUIbooleanCheck if item drop is allowed inside this GUIbooleanCheck if item placement is allowed inside this GUI.booleanCheck if item swap is allowed inside this GUI.booleanCheck if item retrieval is allowed inside this GUI.voidclose(@NotNull org.bukkit.entity.HumanEntity player) Closes the GUI with a2 tickdelay (to prevent items from being taken from theInventory).voidclose(@NotNull org.bukkit.entity.HumanEntity player, boolean runCloseAction) Closes the GUI with a2 tickdelay (to prevent items from being taken from theInventory).@NotNull BaseGuiDisable all the modifications of the GUI, making it immutable by player interaction.@NotNull BaseGuiDisable item drop inside the GUI@NotNull BaseGuiDisable item placement inside the GUI.@NotNull BaseGuiDisable item swap inside the GUI.@NotNull BaseGuiDisable item retrieval inside the GUI.@NotNull BaseGuiDisable other GUI actions This option pretty much disables creating a clone stack of the item@NotNull BaseGuiEnable all modifications of the GUI, making it completely mutable by player interaction.@NotNull BaseGuiAllows item drop inside the GUI@NotNull BaseGuiAllows item placement inside the GUI.@NotNull BaseGuiAllows item swap inside the GUI.@NotNull BaseGuiAllow items to be taken from the GUI.@NotNull BaseGuiEnable other GUI actions This option pretty much enables creating a clone stack of the item@NotNull GuiFillerGets theGuiFillerthat it's used for filling up the GUI in specific ways.@Nullable GuiItemgetGuiItem(int slot) Gets a specificGuiItemon the slot.Gets an immutableMapwith all the GUI items.@NotNull org.bukkit.inventory.InventoryGets the mainInventoryof this GUI.intgetRows()Gets the amount ofrows.@NotNull StringgetTitle()Deprecated.@NotNull GuiTypeguiType()Gets theGuiTypein use.booleanChecks whether or not the GUI is updating.voidopen(@NotNull org.bukkit.entity.HumanEntity player) Opens the GUI for aHumanEntity.voidremoveItem(int slot) Removes theGuiItemin the specific slot.voidremoveItem(int row, int col) AlternativeremoveItem(int)with cols and rows.voidremoveItem(@NotNull GuiItem item) Removes the givenGuiItemfrom the GUI.voidremoveItem(@NotNull org.bukkit.inventory.ItemStack item) Removes the givenItemStackfrom the GUI.voidsetCloseGuiAction(@Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryCloseEvent> closeGuiAction) Sets theGuiActionto run once the inventory is closed.voidsetDefaultClickAction(@Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> defaultClickAction) Sets theGuiActionof a default click on any item.voidsetDefaultTopClickAction(@Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> defaultTopClickAction) Sets theGuiActionof a default click on any item on the top part of the GUI.voidsetDragAction(@Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryDragEvent> dragAction) Sets theGuiActionof a default drag action.voidsetInventory(@NotNull org.bukkit.inventory.Inventory inventory) Sets the new inventory of the GUI.voidAlternativesetItem(int, GuiItem)to set item that uses ROWS and COLUMNS instead of slots.voidSets theGuiItemto a specific slot on the GUI.voidAlternativesetItem(int, GuiItem)to set item that takes aListof slots instead.voidsetOpenGuiAction(@Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryOpenEvent> openGuiAction) Sets theGuiActionto run when the GUI opens.voidsetOutsideClickAction(@Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> outsideClickAction) Sets theGuiActionto run when clicking on the outside of the inventory.voidsetPlayerInventoryAction(@Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> playerInventoryAction) voidsetUpdating(boolean updating) Sets the updating status of the GUI.@NotNull net.kyori.adventure.text.Componenttitle()Gets the GUI title as aComponent.voidupdate()Updates the GUI for all theInventoryviews.voidupdateItem(int row, int col, @NotNull GuiItem item) AlternativeupdateItem(int, GuiItem)that takes ROWS and COLUMNS instead of slots.voidupdateItem(int row, int col, @NotNull org.bukkit.inventory.ItemStack itemStack) AlternativeupdateItem(int, ItemStack)that takes ROWS and COLUMNS instead of slots.voidupdateItem(int slot, @NotNull GuiItem item) AlternativeupdateItem(int, ItemStack)but creates a newGuiItem.voidupdateItem(int slot, @NotNull org.bukkit.inventory.ItemStack itemStack) Updates the specified item in the GUI at runtime, without creating a newGuiItem.@NotNull BaseGuiupdateTitle(@NotNull String title) Updates the title of the GUI.
-
Constructor Details
-
BaseGui
public BaseGui(int rows, @NotNull @NotNull String title, @NotNull @NotNull Set<InteractionModifier> interactionModifiers) The main constructor, usingString.- Parameters:
rows- The amount of rows to use.title- The GUI title usingString.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 takesGuiTypeinstead of rows number. -
BaseGui
Deprecated.In favor ofBaseGui(int, String, Set).Legacy constructor that takes rows and title.- Parameters:
rows- The amount of rows the GUI should have.title- The GUI title.
-
BaseGui
Deprecated.In favor ofBaseGui(GuiType, String, Set).Alternative constructor that takesGuiTypeinstead of rows number.- Parameters:
guiType- TheGuiTypeto use.title- The GUI title.
-
-
Method Details
-
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 aComponent.- Returns:
- The GUI title
Component.
-
setItem
Sets theGuiItemto a specific slot on the GUI.- Parameters:
slot- The GUI slot.guiItem- TheGuiItemto add to the slot.
-
removeItem
Removes the givenGuiItemfrom the GUI.- Parameters:
item- The item to remove.
-
removeItem
public void removeItem(@NotNull @NotNull org.bukkit.inventory.ItemStack item) Removes the givenItemStackfrom the GUI.- Parameters:
item- The item to remove.
-
removeItem
public void removeItem(int slot) Removes theGuiItemin 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
AlternativesetItem(int, GuiItem)to set item that takes aListof slots instead.- Parameters:
slots- The slots in which the item should go.guiItem- TheGuiItemto 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- TheGuiItemto add to the slot.
-
addItem
AddsGuiItems to the GUI without specific slot. It'll set the item to the next empty slot available.- Parameters:
items- Varargs for specifying theGuiItems.
-
addItem
AddsGuiItems to the GUI without specific slot. It'll set the item to the next empty slot available.- Parameters:
items- Varargs for specifying theGuiItems.expandIfFull- If true, expands the gui if it is full and there are more items to be added
-
addSlotAction
public void addSlotAction(int slot, @Nullable @Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> slotAction) Adds aGuiActionfor when clicking on a specific slot. SeeInventoryClickEvent. -
addSlotAction
public void addSlotAction(int row, int col, @Nullable @Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> slotAction) Alternative method foraddSlotAction(int, GuiAction)to add aGuiActionto 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-GuiActionto resolve when clicking on the slot.
-
getGuiItem
Gets a specificGuiItemon the slot.- Parameters:
slot- The slot of the item.- Returns:
- The
GuiItemon the introduced slot ornullif 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- TheHumanEntityto open the GUI to.
-
close
public void close(@NotNull @NotNull org.bukkit.entity.HumanEntity player) Closes the GUI with a2 tickdelay (to prevent items from being taken from theInventory).- Parameters:
player- TheHumanEntityto close the GUI to.
-
close
public void close(@NotNull @NotNull org.bukkit.entity.HumanEntity player, boolean runCloseAction) Closes the GUI with a2 tickdelay (to prevent items from being taken from theInventory).- Parameters:
player- TheHumanEntityto close the GUI to.runCloseAction- If should or not run the close action.
-
update
public void update()Updates the GUI for all theInventoryviews. -
updateTitle
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 newGuiItem.- Parameters:
slot- The slot of the item to update.itemStack- TheItemStackto 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- TheItemStackto 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- TheGuiItemto 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- TheGuiItemto replace in the original.
-
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.
-
disableItemDrop
Disable item drop inside the GUI- Returns:
- The BaseGui
- Since:
- 3.0.3.
-
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
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.
-
enableItemDrop
Allows item drop inside the GUI- Returns:
- The BaseGui
- Since:
- 3.0.3
-
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
Enable all modifications of the GUI, making it completely mutable by player interaction.- Returns:
- The BaseGui.
- Since:
- 3.0.0.
-
allInteractionsDisabled
public boolean allInteractionsDisabled() -
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
Gets theGuiFillerthat it's used for filling up the GUI in specific ways.- Returns:
- The
GuiFiller.
-
getGuiItems
Gets an immutableMapwith all the GUI items.- Returns:
- The
Mapwith all theguiItems.
-
getInventory
@NotNull public @NotNull org.bukkit.inventory.Inventory getInventory()Gets the mainInventoryof this GUI.- Specified by:
getInventoryin interfaceorg.bukkit.inventory.InventoryHolder- Returns:
- Gets the
Inventoryfrom the holder.
-
setInventory
public void setInventory(@NotNull @NotNull org.bukkit.inventory.Inventory inventory) Sets the new inventory of the GUI.- Parameters:
inventory- The new inventory.
-
getRows
public int getRows()Gets the amount ofrows.- Returns:
- The
rowsof the GUI.
-
guiType
Gets theGuiTypein use.- Returns:
- The
GuiType.
-
setDefaultClickAction
public void setDefaultClickAction(@Nullable @Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> defaultClickAction) Sets theGuiActionof a default click on any item. SeeInventoryClickEvent.- Parameters:
defaultClickAction-GuiActionto resolve when any item is clicked.
-
setDefaultTopClickAction
public void setDefaultTopClickAction(@Nullable @Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> defaultTopClickAction) Sets theGuiActionof a default click on any item on the top part of the GUI. Top inventory being for example chests etc, instead of thePlayerinventory. SeeInventoryClickEvent.- Parameters:
defaultTopClickAction-GuiActionto resolve when clicking on the top inventory.
-
setPlayerInventoryAction
public void setPlayerInventoryAction(@Nullable @Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> playerInventoryAction) -
setDragAction
public void setDragAction(@Nullable @Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryDragEvent> dragAction) Sets theGuiActionof a default drag action. SeeInventoryDragEvent.- Parameters:
dragAction-GuiActionto resolve.
-
setCloseGuiAction
public void setCloseGuiAction(@Nullable @Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryCloseEvent> closeGuiAction) Sets theGuiActionto run once the inventory is closed. SeeInventoryCloseEvent.- Parameters:
closeGuiAction-GuiActionto resolve when the inventory is closed.
-
setOpenGuiAction
public void setOpenGuiAction(@Nullable @Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryOpenEvent> openGuiAction) Sets theGuiActionto run when the GUI opens. SeeInventoryOpenEvent.- Parameters:
openGuiAction-GuiActionto resolve when opening the inventory.
-
setOutsideClickAction
public void setOutsideClickAction(@Nullable @Nullable GuiAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> outsideClickAction) Sets theGuiActionto run when clicking on the outside of the inventory. SeeInventoryClickEvent.- Parameters:
outsideClickAction-GuiActionto resolve when clicking outside of the inventory.
-
BaseGui(int, String, Set).