Package dev.majek.chattools
Class Pagination
- java.lang.Object
-
- dev.majek.chattools.Pagination
-
public class Pagination extends Object
Easily manage multiple pages of components.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPagination.InvalidPageExceptionThrown if an invalid page is provided inrender(int).
-
Constructor Summary
Constructors Constructor Description Pagination(@NotNull net.kyori.adventure.text.Component header, @NotNull String movePageCommand)Create a new pagination.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull PaginationaddLine(@NotNull net.kyori.adventure.text.Component line)Add a line to this pagination.@NotNull PaginationaddLines(@NotNull List<net.kyori.adventure.text.Component> lines)Add lines to this pagination.@NotNull PaginationaddLines(@NotNull net.kyori.adventure.text.Component... lines)Add lines to this pagination.@NotNull net.kyori.adventure.text.Componentfooter()Get the footer for this pagination.@NotNull Paginationfooter(@NotNull net.kyori.adventure.text.Component footer)Set the footer.@NotNull net.kyori.adventure.text.Componentheader()Get the header for this pagination.@NotNull net.kyori.adventure.text.format.TextColorhoverTextColor()Get the text color that will be used for hover text.@NotNull PaginationhoverTextColor(@NotNull net.kyori.adventure.text.format.TextColor hoverTextColor)Set the text color that will be used for hover text.@NotNull net.kyori.adventure.text.format.TextColorinvalidButtonColor()Get the text color that will be used for invalid buttons.@NotNull PaginationinvalidButtonColor(@NotNull net.kyori.adventure.text.format.TextColor invalidButtonColor)Set the text color that will be used for invalid buttons.@NotNull List<net.kyori.adventure.text.Component>lines()Get a list of all lines for the pagination.intlinesPerPage()Get the number of lines per page, not counting the header or footer.@NotNull PaginationlinesPerPage(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int linesPerPage)Set the number of lines per page, not counting the header or footer.intmaxChatWidth()Get the maximum amount of characters allowed per line.@NotNull PaginationmaxChatWidth(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int maxChatWidth)Set the maximum amount of characters allowed per line.@NotNull net.kyori.adventure.text.ComponentnextPageButton()Get the component that will be used as a button for traveling to the next page.@NotNull PaginationnextPageButton(@NotNull net.kyori.adventure.text.Component nextPageButton)Set the component that will be used as a button for traveling to the next page.intnumPages()Get the number of pages for this pagination.@NotNull net.kyori.adventure.text.format.TextColorpageCounterColor()Get the text color that will be used for the page counter.@NotNull PaginationpageCounterColor(@NotNull net.kyori.adventure.text.format.TextColor pageCounterColor)Set the text color that will be used for the page counter.@NotNull net.kyori.adventure.text.ComponentprevPageButton()Get the component that will be used as a button for traveling to the previous page.@NotNull PaginationprevPageButton(@NotNull net.kyori.adventure.text.Component prevPageButton)Set the component that will be used as a button for traveling to the previous page.@NotNull List<net.kyori.adventure.text.Component>render(@org.jetbrains.annotations.Range(from=1L, to=2147483647L) int page)Render a page.voidsendPage(@org.jetbrains.annotations.Range(from=1L, to=2147483647L) int page, @NotNull net.kyori.adventure.audience.Audience audience)Send a rendered page to an audience.@NotNull net.kyori.adventure.text.format.TextColorvalidButtonColor()Get the text color that will be used for valid buttons.@NotNull PaginationvalidButtonColor(@NotNull net.kyori.adventure.text.format.TextColor validButtonColor)Set the text color that will be used for valid buttons.
-
-
-
Constructor Detail
-
Pagination
public Pagination(@NotNull @NotNull net.kyori.adventure.text.Component header, @NotNull @NotNull String movePageCommand)Create a new pagination.- Parameters:
header- the header for the top of the pagemovePageCommand- the command for traversing pages of the pagination, you don't need to include the space, the space and page number will be appended
-
-
Method Detail
-
addLine
@NotNull public @NotNull Pagination addLine(@NotNull @NotNull net.kyori.adventure.text.Component line)
Add a line to this pagination. If the line is longer than the maximum width it will be cut into multiple lines.- Parameters:
line- the line to add.- Returns:
- this pagination
-
addLines
@NotNull public @NotNull Pagination addLines(@NotNull @NotNull List<net.kyori.adventure.text.Component> lines)
Add lines to this pagination. If a line is longer than the maximum width it will be cut into multiple lines.- Parameters:
lines- the lines to add.- Returns:
- this pagination
-
addLines
@NotNull public @NotNull Pagination addLines(@NotNull @NotNull net.kyori.adventure.text.Component... lines)
Add lines to this pagination. If a line is longer than the maximum width it will be cut into multiple lines.- Parameters:
lines- the lines to add.- Returns:
- this pagination
-
numPages
public int numPages()
Get the number of pages for this pagination.- Returns:
- number of pages
-
render
@NotNull public @NotNull List<net.kyori.adventure.text.Component> render(@org.jetbrains.annotations.Range(from=1L, to=2147483647L) int page)
Render a page. This will return a list of lines for the page, including the header at the top and footer at the bottom. You can usesendPage(int, Audience)to easily send a specific page to an audience.- Parameters:
page- the page to render- Returns:
- list of lines for the desired page
-
sendPage
public void sendPage(@org.jetbrains.annotations.Range(from=1L, to=2147483647L) int page, @NotNull @NotNull net.kyori.adventure.audience.Audience audience)Send a rendered page to an audience.- Parameters:
page- the page to renderaudience- the audience to send the page to
-
lines
@NotNull public @NotNull List<net.kyori.adventure.text.Component> lines()
Get a list of all lines for the pagination.- Returns:
- all lines
-
header
@NotNull public @NotNull net.kyori.adventure.text.Component header()
Get the header for this pagination.- Returns:
- the header
-
footer
@NotNull public @NotNull net.kyori.adventure.text.Component footer()
Get the footer for this pagination.- Returns:
- the footer
-
footer
@NotNull public @NotNull Pagination footer(@NotNull @NotNull net.kyori.adventure.text.Component footer)
Set the footer.- Parameters:
footer- the footer- Returns:
- this pagination
-
nextPageButton
@NotNull public @NotNull net.kyori.adventure.text.Component nextPageButton()
Get the component that will be used as a button for traveling to the next page.- Returns:
- the next page button
-
nextPageButton
@NotNull public @NotNull Pagination nextPageButton(@NotNull @NotNull net.kyori.adventure.text.Component nextPageButton)
Set the component that will be used as a button for traveling to the next page.- Parameters:
nextPageButton- the next page button- Returns:
- this pagination
-
prevPageButton
@NotNull public @NotNull net.kyori.adventure.text.Component prevPageButton()
Get the component that will be used as a button for traveling to the previous page.- Returns:
- the previous page button
-
prevPageButton
@NotNull public @NotNull Pagination prevPageButton(@NotNull @NotNull net.kyori.adventure.text.Component prevPageButton)
Set the component that will be used as a button for traveling to the previous page.- Parameters:
prevPageButton- the previous page button- Returns:
- this pagination
-
validButtonColor
@NotNull public @NotNull net.kyori.adventure.text.format.TextColor validButtonColor()
Get the text color that will be used for valid buttons.- Returns:
- the valid button color
-
validButtonColor
@NotNull public @NotNull Pagination validButtonColor(@NotNull @NotNull net.kyori.adventure.text.format.TextColor validButtonColor)
Set the text color that will be used for valid buttons.- Parameters:
validButtonColor- the valid button color- Returns:
- this pagination
-
invalidButtonColor
@NotNull public @NotNull net.kyori.adventure.text.format.TextColor invalidButtonColor()
Get the text color that will be used for invalid buttons.- Returns:
- the invalid button color
-
invalidButtonColor
@NotNull public @NotNull Pagination invalidButtonColor(@NotNull @NotNull net.kyori.adventure.text.format.TextColor invalidButtonColor)
Set the text color that will be used for invalid buttons.- Parameters:
invalidButtonColor- the invalid button color- Returns:
- this pagination
-
pageCounterColor
@NotNull public @NotNull net.kyori.adventure.text.format.TextColor pageCounterColor()
Get the text color that will be used for the page counter.- Returns:
- the page counter color
-
pageCounterColor
@NotNull public @NotNull Pagination pageCounterColor(@NotNull @NotNull net.kyori.adventure.text.format.TextColor pageCounterColor)
Set the text color that will be used for the page counter.- Parameters:
pageCounterColor- the page counter color- Returns:
- this pagination
-
hoverTextColor
@NotNull public @NotNull net.kyori.adventure.text.format.TextColor hoverTextColor()
Get the text color that will be used for hover text.- Returns:
- the hover text color
-
hoverTextColor
@NotNull public @NotNull Pagination hoverTextColor(@NotNull @NotNull net.kyori.adventure.text.format.TextColor hoverTextColor)
Set the text color that will be used for hover text.- Parameters:
hoverTextColor- the hover text color- Returns:
- this pagination
-
linesPerPage
public int linesPerPage()
Get the number of lines per page, not counting the header or footer.- Returns:
- the lines per page
-
linesPerPage
@NotNull public @NotNull Pagination linesPerPage(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int linesPerPage)
Set the number of lines per page, not counting the header or footer.- Parameters:
linesPerPage- the lines per page- Returns:
- this pagination
-
maxChatWidth
public int maxChatWidth()
Get the maximum amount of characters allowed per line. Lines exceeding this value will be cut into separate lines.- Returns:
- the max chat width
-
maxChatWidth
@NotNull public @NotNull Pagination maxChatWidth(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int maxChatWidth)
Set the maximum amount of characters allowed per line. Lines exceeding this value will be cut into separate lines.- Parameters:
maxChatWidth- the max chat width- Returns:
- this pagination
-
-