Interface PaginationBuilder<T>
- Type Parameters:
T- the element type served by the source
- All Known Implementing Classes:
PaginationBuilderImpl
View.paginate*
factories. Builder methods only record the declaration; nothing is registered or validated
as a whole until build(), which validates the combination, registers the token with
the owning view and returns it.
Defaults. When neither layoutChar(char), layout(Layout)
nor patterns(Layout...) is called, the pagination targets layout char 'O'.
The default geometry is normal (page-by-page); scroll() switches to a sliding
window, patterns(Layout...) to cycled per-page patterns.
Async-only options. loadingItem(Function),
onError(PaginationErrorCallback), requestTimeout(Duration),
cacheTtl(Duration) and cacheMaxPages(int) are only legal on a builder
created by View.paginateAsync; calling any of them on another builder makes
build() throw ViewConfigurationException.
All methods return this builder for chaining and reject null arguments with
NullPointerException. Value errors fail at setter time with
IllegalArgumentException; combination errors fail at build() with
ViewConfigurationException.
-
Method Summary
Modifier and TypeMethodDescription@NotNull Pagination<T>build()Validates the declaration, constructs the token and registers it with the owning view.@NotNull PaginationBuilder<T>cacheMaxPages(int maxPages) Bounds the page cache (least-recently-used eviction).@NotNull PaginationBuilder<T>Enables page caching: revisiting a page within the TTL renders from cache without calling the supplier;Pagination.refresh(ViewContext)invalidates the cache.@NotNull PaginationBuilder<T>emptyStateItem(@NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> item, int... slots) Sets an item painted into the given slots when the current page settled with no elements, leaving every other layout slot empty.@NotNull PaginationBuilder<T>fallbackItem(@NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> item) Sets the item painted into page slots not covered by an element (for example the tail of a short last page) and into slots whose element failed on its very first paint.@NotNull PaginationBuilder<T>itemRenderer(@NotNull PaginationItemRenderer<T> renderer) Sets the per-element renderer.@NotNull PaginationBuilder<T>Sets an explicit fill order, silently overridinglayoutChar(char).@NotNull PaginationBuilder<T>layoutChar(char character) Targets every slot of the given character in the view's layout, in row-major order.@NotNull PaginationBuilder<T>loadingItem(@NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> item) Sets the item painted into every page slot while an async load is in flight.@NotNull PaginationBuilder<T>loadingItem(@NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> item, int... slots) Sets the loading item painted only into the given slots while an async load is in flight, leaving every other layout slot empty.@NotNull PaginationBuilder<T>onError(@NotNull PaginationErrorCallback callback) Sets the callback invoked when an async page load fails.@NotNull PaginationBuilder<T>Switches to pattern geometry: pageppaints into the slots of pattern(p - 1) % patterns.length, cycling through the given patterns.@NotNull PaginationBuilder<T>requestTimeout(@NotNull Duration timeout) Enables a per-request timeout: a load exceeding it fails with aTimeoutExceptionand follows the normal error path.@NotNull PaginationBuilder<T>scroll()Switches to sliding-window geometry: each page slides the visible window by exactly one element instead of jumping a full page.
-
Method Details
-
layoutChar
Targets every slot of the given character in the view's layout, in row-major order. Defaults to'O'when never called. The character must exist in the view's layout; both "no layout at all" and "char absent from the layout" are validated at view registration time. An explicitlayout(Layout)silently overrides this value; combining an explicit call withpatterns(Layout...)fails atbuild().- Parameters:
character- the layout character whose slots receive the page items- Returns:
- this builder
-
layout
Sets an explicit fill order, silently overridinglayoutChar(char). An empty layout, or combining withpatterns(Layout...), fails atbuild()withViewConfigurationException.- Parameters:
layout- the explicit fill order for the page items- Returns:
- this builder
-
scroll
Switches to sliding-window geometry: each page slides the visible window by exactly one element instead of jumping a full page. Cannot be combined withpatterns(Layout...)— that fails atbuild().- Returns:
- this builder
-
patterns
Switches to pattern geometry: pageppaints into the slots of pattern(p - 1) % patterns.length, cycling through the given patterns. Cannot be combined with an explicitlayoutChar(char)call,layout(Layout)orscroll(); an empty array or any empty pattern also fails — all atbuild()withViewConfigurationException.- Parameters:
patterns- the per-page slot patterns, cycled in order- Returns:
- this builder
-
itemRenderer
@NotNull @NotNull PaginationBuilder<T> itemRenderer(@NotNull @NotNull PaginationItemRenderer<T> renderer) Sets the per-element renderer. Required — a declaration without a renderer fails atbuild()withViewConfigurationException.- Parameters:
renderer- renders one element of the current page into its component builder- Returns:
- this builder
-
fallbackItem
@NotNull @NotNull PaginationBuilder<T> fallbackItem(@NotNull @NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> item) Sets the item painted into page slots not covered by an element (for example the tail of a short last page) and into slots whose element failed on its very first paint. Evaluated against the session's context at paint time. When absent, uncovered slots are cleared instead.- Parameters:
item- the fallback item factory- Returns:
- this builder
-
emptyStateItem
@NotNull @NotNull PaginationBuilder<T> emptyStateItem(@NotNull @NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> item, int... slots) Sets an item painted into the given slots when the current page settled with no elements, leaving every other layout slot empty. UnlikefallbackItem(Function)— which fills every uncovered slot of every page — this renders only while the current page is empty, and only inslots; when the page has any element it renders nothing. When both are set, the empty page shows the empty-state item (the fallback fill is suppressed for that paint).Slots are absolute container slots and may lie outside the pagination's layout. Evaluated against the session's context once per slot at paint time. A slot bound to a static component or to another pagination fails at open with
ViewConfigurationException.- Parameters:
item- the empty-state item factoryslots- the absolute container slots to paint, at least one, each non-negative- Returns:
- this builder
- Throws:
NullPointerException- ifitemorslotsis nullIllegalArgumentException- ifslotsis empty or contains a negative slot
-
loadingItem
@NotNull @NotNull PaginationBuilder<T> loadingItem(@NotNull @NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> item) Sets the item painted into every page slot while an async load is in flight. Async-only: on a non-async builderbuild()throwsViewConfigurationException.- Parameters:
item- the loading placeholder factory- Returns:
- this builder
-
loadingItem
@NotNull @NotNull PaginationBuilder<T> loadingItem(@NotNull @NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> item, int... slots) Sets the loading item painted only into the given slots while an async load is in flight, leaving every other layout slot empty. The slotted form ofloadingItem(Function); it has the same trigger (shown while loading) and only restricts where the item paints. Async-only: on a non-async builderbuild()throwsViewConfigurationException.Slots are absolute container slots and may lie outside the pagination's layout. Evaluated against the session's context once per slot at paint time. A slot bound to a static component or to another pagination fails at open with
ViewConfigurationException.- Parameters:
item- the loading item factoryslots- the absolute container slots to paint, at least one, each non-negative- Returns:
- this builder
- Throws:
NullPointerException- ifitemorslotsis nullIllegalArgumentException- ifslotsis empty or contains a negative slot
-
onError
Sets the callback invoked when an async page load fails. Async-only: on a non-async builderbuild()throwsViewConfigurationException.- Parameters:
callback- the failure callback- Returns:
- this builder
-
requestTimeout
Enables a per-request timeout: a load exceeding it fails with aTimeoutExceptionand follows the normal error path. Async-only: on a non-async builderbuild()throwsViewConfigurationException.- Parameters:
timeout- the timeout, must be positive- Returns:
- this builder
- Throws:
IllegalArgumentException- iftimeoutis zero or negative
-
cacheTtl
Enables page caching: revisiting a page within the TTL renders from cache without calling the supplier;Pagination.refresh(ViewContext)invalidates the cache. Async-only: on a non-async builderbuild()throwsViewConfigurationException.- Parameters:
ttl- the cache entry freshness window, must be positive- Returns:
- this builder
- Throws:
IllegalArgumentException- ifttlis zero or negative
-
cacheMaxPages
Bounds the page cache (least-recently-used eviction). Defaults to 128. RequirescacheTtl(Duration)— setting it without a TTL fails atbuild()withViewConfigurationException. Async-only: on a non-async builderbuild()throwsViewConfigurationException.- Parameters:
maxPages- the maximum number of cached pages, at least 1- Returns:
- this builder
- Throws:
IllegalArgumentException- ifmaxPagesis below 1
-
build
Validates the declaration, constructs the token and registers it with the owning view. Like every token registration this is legal only while the view's tokens are still open for registration — i.e. from field initializers or the view constructor; the builder construction itself (thepaginate*call) never registers anything, only this method does.- Returns:
- the registered pagination token
- Throws:
ViewConfigurationException- when the renderer is missing; whenpatterns(Layout...)is combined with an explicitlayoutChar(char)call,layout(Layout)orscroll(); when the patterns array or any single pattern, or an explicit layout, is empty; when an async-only option was used on a non-async source; or whencacheMaxPages(int)was set withoutcacheTtl(Duration)IllegalStateException- when called a second time on the same builder ("build() may only be called once per paginate* call") or after the view's token table froze
-