Class BaseModal
java.lang.Object
io.rhythmknights.coreapi.component.modal.BaseModal
- All Implemented Interfaces:
org.bukkit.inventory.InventoryHolder
- Direct Known Subclasses:
Modal,PaginatedModal
Base class that every modal extends.
Contains all the basics for the modal to work.
Main and simplest implementation of this is
Modal.-
Constructor Summary
ConstructorsConstructorDescriptionBaseModal(@NotNull ModalContainer modalContainer, @NotNull Set<InteractionModifier> interactionModifiers) -
Method Summary
Modifier and TypeMethodDescriptionvoidAddsModalItems to the modal without specific slot.voidAddsModalItems to the modal without specific slot.voidaddSlotAction(int row, int col, @Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> slotAction) Alternative method foraddSlotAction(int, ModalAction)to add aModalActionto a specific slot using ROWS and COLUMNS instead of slots.voidaddSlotAction(int slot, @Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> slotAction) Adds aModalActionfor when clicking on a specific slot.booleanbooleanCheck if any other actions are allowed in this modalbooleanCheck if item drop is allowed inside this modalbooleanCheck if item placement is allowed inside this modal.booleanCheck if item swap is allowed inside this modal.booleanCheck if item retrieval is allowed inside this modal.voidclose(@NotNull org.bukkit.entity.HumanEntity player) Closes the modal with a2 tickdelay (to prevent items from being taken from theInventory).voidclose(@NotNull org.bukkit.entity.HumanEntity player, boolean runCloseAction) Closes the modal with a2 tickdelay (to prevent items from being taken from theInventory).@NotNull BaseModalDisable all the modifications of the modal, making it immutable by player interaction.@NotNull BaseModalDisable item drop inside the modal@NotNull BaseModalDisable item placement inside the modal.@NotNull BaseModalDisable item swap inside the modal.@NotNull BaseModalDisable item retrieval inside the modal.@NotNull BaseModalDisable other modal actions This option pretty much disables creating a clone stack of the item@NotNull BaseModalEnable all modifications of the modal, making it completely mutable by player interaction.@NotNull BaseModalAllows item drop inside the modal@NotNull BaseModalAllows item placement inside the modal.@NotNull BaseModalAllows item swap inside the modal.@NotNull BaseModalAllow items to be taken from the modal.@NotNull BaseModalEnable other modal actions This option pretty much enables creating a clone stack of the item@NotNull ModalFillerGets theModalFillerthat it's used for filling up the modal in specific ways.@NotNull org.bukkit.inventory.InventoryGets the mainInventoryof this modal.@Nullable ModalItemgetModalItem(int slot) Gets a specificModalItemon the slot.Gets an immutableMapwith all the modal items.intgetRows()Gets the amount ofmodalContainerrows.booleanChecks whether or not the modal is updating.protected @NotNull ModalContainer@NotNull ModalTypeGets theModalTypein use.voidopen(@NotNull org.bukkit.entity.HumanEntity player) Opens the modal for aHumanEntity.voidremoveItem(int slot) Removes theModalItemin the specific slot.voidremoveItem(int row, int col) AlternativeremoveItem(int)with cols and rows.voidremoveItem(@NotNull ModalItem item) Removes the givenModalItemfrom the modal.voidremoveItem(@NotNull org.bukkit.inventory.ItemStack item) Removes the givenItemStackfrom the modal.voidsetCloseModalAction(@Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryCloseEvent> closeModalAction) Sets theModalActionto run once the inventory is closed.voidsetDefaultClickAction(@Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> defaultClickAction) Sets theModalActionof a default click on any item.voidsetDefaultTopClickAction(@Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> defaultTopClickAction) Sets theModalActionof a default click on any item on the top part of the modal.voidsetDragAction(@Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryDragEvent> dragAction) Sets theModalActionof a default drag action.voidsetInventory(@NotNull org.bukkit.inventory.Inventory inventory) Sets the new inventory of the modal.voidAlternativesetItem(int, ModalItem)to set item that uses ROWS and COLUMNS instead of slots.voidSets theModalItemto a specific slot on the modal.voidAlternativesetItem(int, ModalItem)to set item that takes aListof slots instead.voidsetOpenModalAction(@Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryOpenEvent> openModalAction) Sets theModalActionto run when the modal opens.voidsetOutsideClickAction(@Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> outsideClickAction) Sets theModalActionto run when clicking on the outside of the inventory.voidsetPlayerInventoryAction(@Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> playerInventoryAction) @NotNull BaseModalsetUpdateTitleOnItemClick(boolean enable) Enables or disables title updates when items are clickedvoidsetUpdating(boolean updating) Sets the updating status of the modal.booleanChecks if the modal should update its title on item clicks@NotNull net.kyori.adventure.text.Componenttitle()Gets the modal title as aComponent.voidupdate()Updates the modal for all theInventoryviews.voidupdateItem(int row, int col, @NotNull ModalItem item) AlternativeupdateItem(int, ModalItem)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 ModalItem item) AlternativeupdateItem(int, ItemStack)but creates a newModalItem.voidupdateItem(int slot, @NotNull org.bukkit.inventory.ItemStack itemStack) Updates the specified item in the modal at runtime, without creating a newModalItem.@NotNull BaseModalupdateTitle(@NotNull net.kyori.adventure.text.Component title) Updates the title of the modal.voidupdateTitleOnItemClick(@Nullable ModalItem item, int slot, org.bukkit.event.inventory.InventoryClickEvent event) Updates the title based on item interaction
-
Constructor Details
-
BaseModal
public BaseModal(@NotNull @NotNull ModalContainer modalContainer, @NotNull @NotNull Set<InteractionModifier> interactionModifiers)
-
-
Method Details
-
title
@NotNull public @NotNull net.kyori.adventure.text.Component title()Gets the modal title as aComponent.- Returns:
- The modal title
Component.
-
setItem
Sets theModalItemto a specific slot on the modal.- Parameters:
slot- The modal slot.modalItem- TheModalItemto add to the slot.
-
removeItem
Removes the givenModalItemfrom the modal.- Parameters:
item- The item to remove.
-
removeItem
public void removeItem(@NotNull @NotNull org.bukkit.inventory.ItemStack item) Removes the givenItemStackfrom the modal.- Parameters:
item- The item to remove.
-
removeItem
public void removeItem(int slot) Removes theModalItemin the specific slot.- Parameters:
slot- The modal 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, ModalItem)to set item that takes aListof slots instead.- Parameters:
slots- The slots in which the item should go.modalItem- TheModalItemto add to the slots.
-
setItem
AlternativesetItem(int, ModalItem)to set item that uses ROWS and COLUMNS instead of slots.- Parameters:
row- The modal row number.col- The modal column number.modalItem- TheModalItemto add to the slot.
-
addItem
AddsModalItems to the modal without specific slot. It'll set the item to the next empty slot available.- Parameters:
items- Varargs for specifying theModalItems.
-
addItem
AddsModalItems to the modal without specific slot. It'll set the item to the next empty slot available.- Parameters:
expandIfFull- If true, expands the modal if it is full and there are more items to be addeditems- Varargs for specifying theModalItems.
-
addSlotAction
public void addSlotAction(int slot, @Nullable @Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> slotAction) Adds aModalActionfor when clicking on a specific slot. SeeInventoryClickEvent.- Parameters:
slot- The slot that will trigger theModalAction.slotAction-ModalActionto resolve when clicking on specific slots.
-
addSlotAction
public void addSlotAction(int row, int col, @Nullable @Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> slotAction) Alternative method foraddSlotAction(int, ModalAction)to add aModalActionto 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-ModalActionto resolve when clicking on the slot.
-
getModalItem
Gets a specificModalItemon the slot.- Parameters:
slot- The slot of the item.- Returns:
- The
ModalItemon the introduced slot ornullif doesn't exist.
-
isUpdating
public boolean isUpdating()Checks whether or not the modal is updating.- Returns:
- Whether the modal is updating or not.
-
setUpdating
public void setUpdating(boolean updating) Sets the updating status of the modal.- Parameters:
updating- Sets the modal to the updating status.
-
open
public void open(@NotNull @NotNull org.bukkit.entity.HumanEntity player) Opens the modal for aHumanEntity.- Parameters:
player- TheHumanEntityto open the modal to.
-
close
public void close(@NotNull @NotNull org.bukkit.entity.HumanEntity player) Closes the modal with a2 tickdelay (to prevent items from being taken from theInventory).- Parameters:
player- TheHumanEntityto close the modal to.
-
close
public void close(@NotNull @NotNull org.bukkit.entity.HumanEntity player, boolean runCloseAction) Closes the modal with a2 tickdelay (to prevent items from being taken from theInventory).- Parameters:
player- TheHumanEntityto close the modal to.runCloseAction- If should or not run the close action.
-
update
public void update()Updates the modal for all theInventoryviews. -
updateTitle
@NotNull @Contract("_ -> this") public @NotNull BaseModal updateTitle(@NotNull @NotNull net.kyori.adventure.text.Component title) Updates the title of the modal. This method may cause LAG if used on a loop.- Parameters:
title- The title to set.- Returns:
- The modal 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 modal at runtime, without creating a newModalItem.- Parameters:
slot- The slot of the item to update.itemStack- TheItemStackto replace in the original one in theModalItem.
-
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 theModalItem.
-
updateItem
AlternativeupdateItem(int, ItemStack)but creates a newModalItem.- Parameters:
slot- The slot of the item to update.item- TheModalItemto replace in the original.
-
updateItem
AlternativeupdateItem(int, ModalItem)that takes ROWS and COLUMNS instead of slots.- Parameters:
row- The row of the slot.col- The columns of the slot.item- TheModalItemto replace in the original.
-
disableItemPlace
Disable item placement inside the modal.- Returns:
- The BaseModal.
- Since:
- 3.0.0.
-
disableItemTake
Disable item retrieval inside the modal.- Returns:
- The BaseModal.
- Since:
- 3.0.0.
-
disableItemSwap
Disable item swap inside the modal.- Returns:
- The BaseModal.
- Since:
- 3.0.0.
-
disableItemDrop
Disable item drop inside the modal- Returns:
- The BaseModal
- Since:
- 3.0.3.
-
disableOtherActions
Disable other modal actions This option pretty much disables creating a clone stack of the item- Returns:
- The BaseModal
- Since:
- 3.0.4
-
disableAllInteractions
Disable all the modifications of the modal, making it immutable by player interaction.- Returns:
- The BaseModal.
- Since:
- 3.0.0.
-
enableItemPlace
Allows item placement inside the modal.- Returns:
- The BaseModal.
- Since:
- 3.0.0.
-
enableItemTake
Allow items to be taken from the modal.- Returns:
- The BaseModal.
- Since:
- 3.0.0.
-
enableItemSwap
Allows item swap inside the modal.- Returns:
- The BaseModal.
- Since:
- 3.0.0.
-
enableItemDrop
Allows item drop inside the modal- Returns:
- The BaseModal
- Since:
- 3.0.3
-
enableOtherActions
Enable other modal actions This option pretty much enables creating a clone stack of the item- Returns:
- The BaseModal
- Since:
- 3.0.4
-
enableAllInteractions
Enable all modifications of the modal, making it completely mutable by player interaction.- Returns:
- The BaseModal.
- Since:
- 3.0.0.
-
allInteractionsDisabled
public boolean allInteractionsDisabled() -
canPlaceItems
public boolean canPlaceItems()Check if item placement is allowed inside this modal.- Returns:
- True if item placement is allowed for this modal.
- Since:
- 3.0.0.
-
canTakeItems
public boolean canTakeItems()Check if item retrieval is allowed inside this modal.- Returns:
- True if item retrieval is allowed inside this modal.
- Since:
- 3.0.0.
-
canSwapItems
public boolean canSwapItems()Check if item swap is allowed inside this modal.- Returns:
- True if item swap is allowed for this modal.
- Since:
- 3.0.0.
-
canDropItems
public boolean canDropItems()Check if item drop is allowed inside this modal- Returns:
- True if item drop is allowed for this modal
- Since:
- 3.0.3
-
allowsOtherActions
public boolean allowsOtherActions()Check if any other actions are allowed in this modal- Returns:
- True if other actions are allowed
- Since:
- 3.0.4
-
getFiller
Gets theModalFillerthat it's used for filling up the modal in specific ways.- Returns:
- The
ModalFiller.
-
getModalItems
Gets an immutableMapwith all the modal items.- Returns:
- The
Mapwith all themodalItems.
-
getInventory
@NotNull public @NotNull org.bukkit.inventory.Inventory getInventory()Gets the mainInventoryof this modal.- 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 modal.- Parameters:
inventory- The new inventory.
-
getRows
public int getRows()Gets the amount ofmodalContainerrows.- Returns:
- The
modalContainer's rows of the modal.
-
modalType
Gets theModalTypein use.- Returns:
- The
ModalType.
-
setDefaultClickAction
public void setDefaultClickAction(@Nullable @Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> defaultClickAction) Sets theModalActionof a default click on any item. SeeInventoryClickEvent.- Parameters:
defaultClickAction-ModalActionto resolve when any item is clicked.
-
setDefaultTopClickAction
public void setDefaultTopClickAction(@Nullable @Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> defaultTopClickAction) Sets theModalActionof a default click on any item on the top part of the modal. Top inventory being for example chests etc, instead of thePlayerinventory. SeeInventoryClickEvent.- Parameters:
defaultTopClickAction-ModalActionto resolve when clicking on the top inventory.
-
setPlayerInventoryAction
public void setPlayerInventoryAction(@Nullable @Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> playerInventoryAction) -
setDragAction
public void setDragAction(@Nullable @Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryDragEvent> dragAction) Sets theModalActionof a default drag action. SeeInventoryDragEvent.- Parameters:
dragAction-ModalActionto resolve.
-
setCloseModalAction
public void setCloseModalAction(@Nullable @Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryCloseEvent> closeModalAction) Sets theModalActionto run once the inventory is closed. SeeInventoryCloseEvent.- Parameters:
closeModalAction-ModalActionto resolve when the inventory is closed.
-
setOpenModalAction
public void setOpenModalAction(@Nullable @Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryOpenEvent> openModalAction) Sets theModalActionto run when the modal opens. SeeInventoryOpenEvent.- Parameters:
openModalAction-ModalActionto resolve when opening the inventory.
-
setOutsideClickAction
public void setOutsideClickAction(@Nullable @Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> outsideClickAction) Sets theModalActionto run when clicking on the outside of the inventory. SeeInventoryClickEvent.- Parameters:
outsideClickAction-ModalActionto resolve when clicking outside of the inventory.
-
setUpdateTitleOnItemClick
Enables or disables title updates when items are clicked- Parameters:
enable- Whether to update title on item clicks- Returns:
- The modal for easier use when declaring
-
shouldUpdateTitleOnItemClick
public boolean shouldUpdateTitleOnItemClick()Checks if the modal should update its title on item clicks- Returns:
- True if title should update on item clicks
-
updateTitleOnItemClick
public void updateTitleOnItemClick(@Nullable @Nullable ModalItem item, int slot, org.bukkit.event.inventory.InventoryClickEvent event) Updates the title based on item interaction- Parameters:
item- The clicked modal itemslot- The slot that was clickedevent- The inventory click event
-
modalContainer
-