java.lang.Object
com.datdeveloper.datmoddingapi.command.util.Pager<T>
Type Parameters:
T - The type of the item being paged

public class Pager<T> extends Object
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 Classes
    Modifier and Type
    Class
    Description
    static interface 
    A Functional interface to transform the given PagedElement into a Chat Component
  • Constructor Summary

    Constructors
    Constructor
    Description
    Pager(@NotNull String command, @Nullable String headerText, int elementsPerPage, @NotNull Collection<? extends T> elements, @NotNull Pager.ElementTransformer<T> transformer)
    Construct a pager
    Pager(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 Type
    Method
    Description
    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
    protected net.minecraft.network.chat.Component
    getFooter(int page)
    Get the footer for the page
    This will generate the navigation buttons, accounting for which buttons are enabled
    protected net.minecraft.network.chat.Component
    Get the header for the pager
    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
    void
    sendPage(int page, net.minecraft.commands.CommandSource source)
    Send the given page to the given CommandSource

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 used
      headerText - The heading of the pager
      elements - A list of the elements being paged
      transformer - 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 used
      headerText - The heading of the pager
      elementsPerPage - The amount of elements per page
      elements - A list of the elements being paged
      transformer - 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
    • getFooter

      protected net.minecraft.network.chat.Component getFooter(int page)
      Get the footer for the page
      This will generate the navigation buttons, accounting for which buttons are enabled
      Parameters:
      page - The page the footer is for
      Returns:
      The footer
    • 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 given CommandSource
      Parameters:
      page - The page to show to the CommandSource
      source - The command source to send the page to