Class Pagination
java.lang.Object
io.github.rysefoxx.inventory.plugin.pagination.Pagination
- Since:
- 2/19/2022
-
Constructor Summary
ConstructorsConstructorDescriptionPagination(@NotNull Pagination pagination) Pagination(@NotNull RyseInventory inventory) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddInventoryData(IntelligentItemData itemData) Adds the given item data to the inventory data.voidaddItem(@NotNull IntelligentItem item) Adds a single intelligent ItemStack.voidaddItem(@NotNull org.bukkit.inventory.ItemStack itemStack) Adds a single ItemStack.voidaddItem(@NotNull org.bukkit.inventory.ItemStack itemStack, @NotNull IntelligentType type) Adds a single ItemStack.@Nullable IntelligentItemget(int slot) Returns the item in the specified slot, or null if the slot is empty.@Nullable IntelligentItemget(int slot, int page) Return the item in the given slot on the given page, or null if there is no item in that slot.protected @NotNull List<IntelligentItemData>getDataByPage(int page) This function returns a list of all the items on the specified page.@NotNull List<IntelligentItemData>Returns the inventory data of the player.@Nullable IntelligentItemgetPresent(int slot) Returns the item in the specified slot, or null if the slot is empty.@NotNull RyseInventorybooleanisFirst()booleanisLast()voiditerator(@NotNull SlotIterator slotIterator) Sets the SlotIterator for the paginationintlastPage()@NotNull PaginationnewInstance(@NotNull Pagination pagination) Creates a new instance of Pagination where all data is transferred along.@NotNull Paginationnext()Increases the current page by 1intpage()page(int page) Sets the current page to the specified page.@NotNull Paginationprevious()Decreases the current page by 1voidremove(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 functionprotected voidremove(int slot, int page) Removes all inventory data from the list that matches the given page and slotvoidsetItem(int slot, int page, @NotNull IntelligentItem newItem, boolean transfer) Sets a new item at a slot with defined a page.voidsetItem(int slot, @NotNull IntelligentItem newItem) Sets a new item at a slot.voidsetItems(@NotNull List<IntelligentItem> items) Sets a complete list of smart ItemStacksvoidsetItems(IntelligentItem @NotNull [] items) Sets a complete list of smart ItemStacksvoidsetItemsPerPage(int itemsPerPage) protected voidsetPage(int page) This function sets the page number.
-
Constructor Details
-
Pagination
- Parameters:
inventory- The inventory where the pagination is used. Pagination constructor with a default size of 1 element per page.
-
Pagination
-
-
Method Details
-
newInstance
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
- 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
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
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
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
Sets a complete list of smart ItemStacks- Parameters:
items- A list of intelligent ItemStacks
-
setItems
Sets a complete list of smart ItemStacks- Parameters:
items- An array of smart ItemStacks
-
addItem
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 ItemStacktype- the type of the ItemStack
-
iterator
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 slotnewItem- 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 tonewItem- The Item to settransfer- If the item should be transferred to the next page.- Throws:
IllegalArgumentException- if slot greater than 53First 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 modifiedpage- The page of the inventory.
-
get
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
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
Returns the inventory data of the player.- Returns:
- A list of IntelligentItemData objects.
-
addInventoryData
Adds the given item data to the inventory data.- Parameters:
itemData- The IntelligentItemData object that you want to add to the inventory.
-
getDataByPage
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.
-