Class BaseModal

java.lang.Object
io.rhythmknights.coreapi.component.modal.BaseModal
All Implemented Interfaces:
org.bukkit.inventory.InventoryHolder
Direct Known Subclasses:
Modal, PaginatedModal

public abstract class BaseModal extends Object implements org.bukkit.inventory.InventoryHolder
Base class that every modal extends. Contains all the basics for the modal to work. Main and simplest implementation of this is Modal.
  • Constructor Details

  • Method Details

    • title

      @NotNull public @NotNull net.kyori.adventure.text.Component title()
      Gets the modal title as a Component.
      Returns:
      The modal title Component.
    • setItem

      public void setItem(int slot, @NotNull @NotNull ModalItem modalItem)
      Sets the ModalItem to a specific slot on the modal.
      Parameters:
      slot - The modal slot.
      modalItem - The ModalItem to add to the slot.
    • removeItem

      public void removeItem(@NotNull @NotNull ModalItem item)
      Removes the given ModalItem from the modal.
      Parameters:
      item - The item to remove.
    • removeItem

      public void removeItem(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Removes the given ItemStack from the modal.
      Parameters:
      item - The item to remove.
    • removeItem

      public void removeItem(int slot)
      Removes the ModalItem in the specific slot.
      Parameters:
      slot - The modal 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 ModalItem modalItem)
      Alternative setItem(int, ModalItem) to set item that takes a List of slots instead.
      Parameters:
      slots - The slots in which the item should go.
      modalItem - The ModalItem to add to the slots.
    • setItem

      public void setItem(int row, int col, @NotNull @NotNull ModalItem modalItem)
      Alternative setItem(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 - The ModalItem to add to the slot.
    • addItem

      public void addItem(@NotNull @NotNull ModalItem... items)
      Adds ModalItems to the modal without specific slot. It'll set the item to the next empty slot available.
      Parameters:
      items - Varargs for specifying the ModalItems.
    • addItem

      public void addItem(boolean expandIfFull, @NotNull @NotNull ModalItem... items)
      Adds ModalItems 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 added
      items - Varargs for specifying the ModalItems.
    • addSlotAction

      public void addSlotAction(int slot, @Nullable @Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> slotAction)
      Adds a ModalAction for when clicking on a specific slot. See InventoryClickEvent.
      Parameters:
      slot - The slot that will trigger the ModalAction.
      slotAction - ModalAction to 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 for addSlotAction(int, ModalAction) to add a ModalAction 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 - ModalAction to resolve when clicking on the slot.
    • getModalItem

      @Nullable public @Nullable ModalItem getModalItem(int slot)
      Gets a specific ModalItem on the slot.
      Parameters:
      slot - The slot of the item.
      Returns:
      The ModalItem on the introduced slot or null if 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 a HumanEntity.
      Parameters:
      player - The HumanEntity to open the modal to.
    • close

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

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

      public void update()
      Updates the modal for all the Inventory views.
    • 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 new ModalItem.
      Parameters:
      slot - The slot of the item to update.
      itemStack - The ItemStack to replace in the original one in the ModalItem.
    • 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 ModalItem.
    • updateItem

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      @NotNull public @NotNull Map<@NotNull Integer,@NotNull ModalItem> getModalItems()
      Gets an immutable Map with all the modal items.
      Returns:
      The Map with all the modalItems.
    • getInventory

      @NotNull public @NotNull org.bukkit.inventory.Inventory getInventory()
      Gets the main Inventory of this modal.
      Specified by:
      getInventory in interface org.bukkit.inventory.InventoryHolder
      Returns:
      Gets the Inventory from 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 of modalContainer rows.
      Returns:
      The modalContainer's rows of the modal.
    • modalType

      @NotNull public @NotNull ModalType modalType()
      Gets the ModalType in use.
      Returns:
      The ModalType.
    • setDefaultClickAction

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

      public void setDefaultTopClickAction(@Nullable @Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryClickEvent> defaultTopClickAction)
      Sets the ModalAction of a default click on any item on the top part of the modal. Top inventory being for example chests etc, instead of the Player inventory. See InventoryClickEvent.
      Parameters:
      defaultTopClickAction - ModalAction to 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 the ModalAction of a default drag action. See InventoryDragEvent.
      Parameters:
      dragAction - ModalAction to resolve.
    • setCloseModalAction

      public void setCloseModalAction(@Nullable @Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryCloseEvent> closeModalAction)
      Sets the ModalAction to run once the inventory is closed. See InventoryCloseEvent.
      Parameters:
      closeModalAction - ModalAction to resolve when the inventory is closed.
    • setOpenModalAction

      public void setOpenModalAction(@Nullable @Nullable ModalAction<@NotNull org.bukkit.event.inventory.InventoryOpenEvent> openModalAction)
      Sets the ModalAction to run when the modal opens. See InventoryOpenEvent.
      Parameters:
      openModalAction - ModalAction to resolve when opening the inventory.
    • setOutsideClickAction

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

      @NotNull @Contract("_ -> this") public @NotNull BaseModal setUpdateTitleOnItemClick(boolean enable)
      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 item
      slot - The slot that was clicked
      event - The inventory click event
    • modalContainer

      @NotNull protected @NotNull ModalContainer modalContainer()