java.lang.Object
io.github.rysefoxx.inventory.plugin.pagination.Pagination

public class Pagination extends Object
Since:
2/19/2022
  • Constructor Details

    • Pagination

      public Pagination(@NotNull @NotNull RyseInventory inventory)
      Parameters:
      inventory - The inventory where the pagination is used. Pagination constructor with a default size of 1 element per page.
    • Pagination

      public Pagination(@NotNull @NotNull Pagination pagination)
  • Method Details

    • newInstance

      @NotNull public @NotNull Pagination newInstance(@NotNull @NotNull Pagination pagination)
      Creates a new instance of Pagination where all data is transferred along.
      Parameters:
      pagination - The pagination to copy from.
      Returns:
      The new instance of Pagination.
    • page

      @Nonnegative public int page()
      Returns:
      the current page.
    • lastPage

      @Nonnegative public int lastPage()
      Returns:
      the last page.
    • inventory

      @NotNull public @NotNull RyseInventory inventory()
      Returns:
      the current inventory.
    • isLast

      public boolean isLast()
      Returns:
      true if you are on the last page.
    • isFirst

      public boolean isFirst()
      Returns:
      true if you are on the first page.
    • next

      @NotNull public @NotNull Pagination next() throws IllegalStateException
      Increases the current page by 1
      Returns:
      the new Pagination
      Throws:
      IllegalStateException - if you are on the last page and you try to increase the page.
    • previous

      @NotNull public @NotNull Pagination previous() throws IllegalStateException
      Decreases the current page by 1
      Returns:
      the new Pagination
      Throws:
      IllegalStateException - if you are on the first page and you try to decrease the page.
    • page

      public Pagination page(@Nonnegative int page)
      Sets the current page to the specified page.
      Parameters:
      page - The page to set to.
      Returns:
      the new Pagination

      This will not check if the page is valid.

    • setItems

      public void setItems(@NotNull @NotNull List<IntelligentItem> items)
      Sets a complete list of smart ItemStacks
      Parameters:
      items - A list of intelligent ItemStacks
    • setItems

      public void setItems(IntelligentItem @NotNull [] items)
      Sets a complete list of smart ItemStacks
      Parameters:
      items - An array of smart ItemStacks
    • addItem

      public void addItem(@NotNull @NotNull IntelligentItem item)
      Adds a single intelligent ItemStack.
      Parameters:
      item - the intelligent ItemStack
    • addItem

      public void addItem(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack)
      Adds a single ItemStack.
      Parameters:
      itemStack - the ItemStack
    • addItem

      public void addItem(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack, @NotNull @NotNull IntelligentType type)
      Adds a single ItemStack.
      Parameters:
      itemStack - the ItemStack
      type - the type of the ItemStack
    • iterator

      public void iterator(@NotNull @NotNull SlotIterator slotIterator)
      Sets the SlotIterator for the pagination
      Parameters:
      slotIterator - the SlotIterator
    • setItem

      public void setItem(@Nonnegative int slot, @NotNull @NotNull IntelligentItem newItem) throws IllegalArgumentException
      Sets a new item at a slot.
      Parameters:
      slot - The slot
      newItem - The Item
      Throws:
      IllegalArgumentException - if slot greater than 53
    • setItem

      @Internal public void setItem(@Nonnegative int slot, @Nonnegative int page, @NotNull @NotNull IntelligentItem newItem, boolean transfer) throws IllegalArgumentException
      Sets a new item at a slot with defined a page.
      Parameters:
      slot - The slot to set the item at.
      page - The page to set the item to
      newItem - The Item to set
      transfer - If the item should be transferred to the next page.
      Throws:
      IllegalArgumentException - if slot greater than 53

      First page is 0

    • setItemsPerPage

      public void setItemsPerPage(@Nonnegative int itemsPerPage)
      Parameters:
      itemsPerPage - How many items may be per page.

      If you have set the endPosition at the SlotIterator, it will be preferred.

    • remove

      @Internal public void remove(@Nonnegative int slot)
      It removes all inventory data from the inventory data list that has the same page and slot as the page and slot that was passed into the function
      Parameters:
      slot - The slot to remove the item from.
    • remove

      protected void remove(@Nonnegative int slot, @Nonnegative int page)
      Removes all inventory data from the list that matches the given page and slot
      Parameters:
      slot - The slot that was modified
      page - The page of the inventory.
    • get

      @Internal @Nullable public @Nullable IntelligentItem get(@Nonnegative int slot)
      Returns the item in the specified slot, or null if the slot is empty.
      Parameters:
      slot - The slot number of the item you want to get.
      Returns:
      The item in the slot.
    • getPresent

      @Internal @Nullable public @Nullable IntelligentItem getPresent(@Nonnegative int slot)
      Returns the item in the specified slot, or null if the slot is empty.
      Parameters:
      slot - The slot number of the item you want to get.
      Returns:
      The item in the slot.
    • get

      @Internal @Nullable public @Nullable IntelligentItem get(@Nonnegative int slot, @Nonnegative int page)
      Return the item in the given slot on the given page, or null if there is no item in that slot.

      The first thing we do is filter the inventory data to only include data that matches the given page and slot. Then we use `findFirst()` to get the first item in the stream, if there is one. If there is an item, we use `map()` to get the item from the data. If there is no item, we use `orElse()` to return null

      Parameters:
      slot - The slot number of the item you want to get.
      page - The page number of the inventory.
      Returns:
      The item in the slot and page.
    • getInventoryData

      @Internal @NotNull public @NotNull List<IntelligentItemData> getInventoryData()
      Returns the inventory data of the player.
      Returns:
      A list of IntelligentItemData objects.
    • addInventoryData

      protected void addInventoryData(IntelligentItemData itemData)
      Adds the given item data to the inventory data.
      Parameters:
      itemData - The IntelligentItemData object that you want to add to the inventory.
    • getDataByPage

      @NotNull protected @NotNull List<IntelligentItemData> getDataByPage(@Nonnegative int page)
      This function returns a list of all the items on the specified page.
      Parameters:
      page - The page number to get the data from.
      Returns:
      A list of IntelligentItemData objects.
    • setPage

      protected void setPage(@Nonnegative int page)
      This function sets the page number.
      Parameters:
      page - The page number to get.