Class Pager<T>
java.lang.Object
com.datdeveloper.datmoddingapi.command.util.Pager<T>
- Type Parameters:
T- The type of the item being paged
A class to split the results of a command into pages Commands that implement this should take an integer as the last
argument that is passed to the
sendPage(int, CommandSource) method-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA Functional interface to transform the given PagedElement into a Chat Component -
Constructor Summary
ConstructorsConstructorDescriptionPager(@NotNull String command, @Nullable String headerText, int elementsPerPage, @NotNull Collection<? extends T> elements, @NotNull Pager.ElementTransformer<T> transformer) Construct a pagerPager(String command, @Nullable String headerText, Collection<? extends T> elements, Pager.ElementTransformer<T> transformer) Construct a pager with the default amount of items per page (10) -
Method Summary
Modifier and TypeMethodDescriptionprotected net.minecraft.network.chat.ComponentgetBody(int page) Get the body of the page
This performs the transformations on the snippet of the elements, formatted as a listprotected net.minecraft.network.chat.ComponentgetFooter(int page) Get the footer for the page
This will generate the navigation buttons, accounting for which buttons are enabledprotected net.minecraft.network.chat.ComponentGet the header for the pagernet.minecraft.network.chat.ComponentrenderPage(int page) Render the page of the pager
This produces a full component ready to display to the user, with the header, body, and footer, rendered and combinedvoidsendPage(int page, net.minecraft.commands.CommandSource source) Send the given page to the givenCommandSource
-
Constructor Details
-
Pager
public Pager(String command, @Nullable @Nullable String headerText, Collection<? extends T> elements, Pager.ElementTransformer<T> transformer) Construct a pager with the default amount of items per page (10)- Parameters:
command- The command usedheaderText- The heading of the pagerelements- A list of the elements being pagedtransformer- The function that converts the elements into a chat component
-
Pager
public Pager(@NotNull @NotNull String command, @Nullable @Nullable String headerText, int elementsPerPage, @NotNull @NotNull Collection<? extends T> elements, @NotNull @NotNull Pager.ElementTransformer<T> transformer) Construct a pager- Parameters:
command- The command usedheaderText- The heading of the pagerelementsPerPage- The amount of elements per pageelements- A list of the elements being pagedtransformer- The function that converts the elements into a chat component
-
-
Method Details
-
getHeader
protected net.minecraft.network.chat.Component getHeader()Get the header for the pager- Returns:
- The header for the pager
-
getBody
protected net.minecraft.network.chat.Component getBody(int page) Get the body of the page
This performs the transformations on the snippet of the elements, formatted as a list- Parameters:
page- The page the body is for- Returns:
- the body
-
renderPage
public net.minecraft.network.chat.Component renderPage(int page) Render the page of the pager
This produces a full component ready to display to the user, with the header, body, and footer, rendered and combined- Parameters:
page- The page to render- Returns:
- The fully rendered page of the pager
-
sendPage
public void sendPage(int page, net.minecraft.commands.CommandSource source) Send the given page to the givenCommandSource- Parameters:
page- The page to show to the CommandSourcesource- The command source to send the page to
-