Class LazyPaginateHelper

java.lang.Object
com.github.ygimenez.model.helper.BaseHelper<LazyPaginateHelper,​List<Page>>
com.github.ygimenez.model.helper.LazyPaginateHelper

public class LazyPaginateHelper extends BaseHelper<LazyPaginateHelper,​List<Page>>
Helper class for building lazy-paginate events, safe for reuse.
  • Constructor Details

    • LazyPaginateHelper

      public LazyPaginateHelper(ThrowingFunction<Integer,​Page> pageLoader, boolean useButtons)
      Creates a new lazy-paginate event helper with the supplied page loader and default list implementation (ArrayList).
      Parameters:
      pageLoader - The lazy loader used to generate pages. The value supplied is the current page number.
      useButtons - Whether to use interaction buttons or legacy reaction-based buttons.
    • LazyPaginateHelper

      public LazyPaginateHelper(ThrowingFunction<Integer,​Page> pageLoader, @Nullable List<Page> initialPages, boolean useButtons)
      Creates a new lazy-paginate event helper with the supplied page loader and a list of initially loaded pages.
      Parameters:
      pageLoader - The lazy loader used to generate pages. The value supplied is the current page number.
      initialPages - A List containing the initially available pages.
      useButtons - Whether to use interaction buttons or legacy reaction-based buttons.
  • Method Details

    • addPage

      public LazyPaginateHelper addPage(Page page)
      Adds a new page to the list.
      Parameters:
      page - The page to be added.
      Returns:
      The LazyPaginateHelper instance for chaining convenience.
    • getPageLoader

      public ThrowingFunction<Integer,​Page> getPageLoader()
      Retrieves the configured page loader for this helper.
      Returns:
      The page loader Function
    • load

      @Nullable public Page load(int page)
      Loads the page represented by the specified index. Might be null, meaning there's no page available for that index.
      Parameters:
      page - The page index.
      Returns:
      The page returned by the loader.
    • getComponents

      public <Out extends net.dv8tion.jda.api.utils.messages.MessageRequest<Out>> List<net.dv8tion.jda.api.interactions.components.LayoutComponent> getComponents(Out action)
      Description copied from class: BaseHelper
      Retrieves the List of Components generated by this helper.
      Specified by:
      getComponents in class BaseHelper<LazyPaginateHelper,​List<Page>>
      Type Parameters:
      Out - Generic for a MessageRequest
      Parameters:
      action - A message event (either create or edit).
      Returns:
      The list of components.
    • shouldUpdate

      public boolean shouldUpdate(net.dv8tion.jda.api.entities.Message msg)
      Calculates whether the Message needs to have buttons applied onto or not.
      Specified by:
      shouldUpdate in class BaseHelper<LazyPaginateHelper,​List<Page>>
      Parameters:
      msg - The Message to be checked.
      Returns:
      Whether it needs to be updated or not.