Class View
@RegisterView and opened through ViewService; subclasses override only the
lifecycle handlers they need. All handlers run on the main thread, invoked by the engine.
Contract: view fields hold only state tokens, injected collaborators and immutable
configuration — every per-player value lives in per-context state and is dropped when the
context closes. State factories are legal only in field initializers or the constructor;
after registration freezes the token table they throw IllegalStateException.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final <T> MutableState<T>initialState(@NotNull String key, @NotNull Class<T> type) Declares a mutable value bound fromViewArgumentsat open; the type is validated at the open site.protected final <T> State<T>lazyState(@NotNull Function<ViewContext, T> computation) Declares a read-only value computed once per context on the first read, on the main thread, and stored thereafter.protected final <T> MutableState<T>mutableState(@NotNull Function<ViewContext, T> initialValue) Declares a per-context mutable value whose initial is computed per context on first read, e.g.protected final <T> MutableState<T>mutableState(T initialValue) Declares a per-context mutable value seeded with a shared initial value.protected voidonClick(@NotNull SlotClickContext context) View-level click fallback: runs after component handlers for top-container clicks and receives every bottom-inventory click withisPlayerInventory() == true.protected voidonClose(@NotNull CloseContext context) Called when the session tears down, with the matchingCloseReason.protected voidonFirstRender(@NotNull RenderContext context) Declares this session's components; called once per open, after the container is created and before the first paint.protected voidonInit(@NotNull ViewConfigBuilder config) Configures this view; called once per class at registration.protected voidonOpen(@NotNull OpenContext context) Called once per open, before any container exists.protected voidonUpdate(@NotNull UpdateContext context) Called on every update pass; inspectUpdateContext.trigger()for the cause.protected final <T> PaginationBuilder<T>paginate(@NotNull Function<ViewContext, List<T>> source) Declares paginated rendering over a per-context element list: the function runs once per context at pagination initialization, on the main thread, and runs again for that context only whenPagination.refresh(context)is called.protected final <T> PaginationBuilder<T>Declares paginated rendering over a fixed element list.protected final <T> PaginationBuilder<T>paginateAsync(@NotNull AsyncPageSupplier<T> source) Declares paginated rendering over an asynchronously loaded source: every context gets its own freshAsyncPageSourceat pagination initialization, so request ids, page caches, loading state and errors are never shared between viewers.protected final <T> PaginationBuilder<T>paginateSource(@NotNull Function<ViewContext, PageSource<T>> factory) Escape hatch declaring paginated rendering over a customPageSource: the factory runs once per context at pagination initialization and must return the source instance serving exactly that context.protected final <T> SharedState<T>sharedState(T initialValue) Declares one atomic value per view singleton, shared by all viewers and writable from any thread.final @NotNull TokenTableReturns this view's token table; used by the engine to size per-session state storage and to freeze token registration.
-
Constructor Details
-
View
public View()
-
-
Method Details
-
onInit
Configures this view; called once per class at registration. The resulting config is validated and frozen afterwards.- Parameters:
config- the mutable config builder
-
onOpen
Called once per open, before any container exists. May cancel the open (zero side effects) or override title/rows for this open only.- Parameters:
context- the open context
-
onFirstRender
Declares this session's components; called once per open, after the container is created and before the first paint.- Parameters:
context- the render context
-
onUpdate
Called on every update pass; inspectUpdateContext.trigger()for the cause.- Parameters:
context- the update context
-
onClick
View-level click fallback: runs after component handlers for top-container clicks and receives every bottom-inventory click withisPlayerInventory() == true.- Parameters:
context- the click context
-
onClose
Called when the session tears down, with the matchingCloseReason. Throwing here is caught and logged; teardown always completes.- Parameters:
context- the close context
-
mutableState
Declares a per-context mutable value seeded with a shared initial value. The initial object is shared by every context and must be immutable; usemutableState(Function)for mutable initials such as collections.- Type Parameters:
T- the value type- Parameters:
initialValue- the shared initial value, possiblynull- Returns:
- the state token
- Throws:
IllegalStateException- when called after registration froze the token table
-
mutableState
protected final <T> MutableState<T> mutableState(@NotNull @NotNull Function<ViewContext, T> initialValue) Declares a per-context mutable value whose initial is computed per context on first read, e.g.mutableState(ctx -> new ArrayList<>()).- Type Parameters:
T- the value type- Parameters:
initialValue- the per-context initial value factory- Returns:
- the state token
- Throws:
IllegalStateException- when called after registration froze the token table
-
lazyState
Declares a read-only value computed once per context on the first read, on the main thread, and stored thereafter.- Type Parameters:
T- the value type- Parameters:
computation- the once-per-context computation- Returns:
- the state token
- Throws:
IllegalStateException- when called after registration froze the token table
-
initialState
protected final <T> MutableState<T> initialState(@NotNull @NotNull String key, @NotNull @NotNull Class<T> type) Declares a mutable value bound fromViewArgumentsat open; the type is validated at the open site. An absent key reads asnulluntil set.- Type Parameters:
T- the value type- Parameters:
key- the argument key bound at opentype- the expected argument type- Returns:
- the state token
- Throws:
IllegalStateException- when called after registration froze the token table
-
paginate
Declares paginated rendering over a fixed element list. The list is copied defensively when this factory runs and becomes one immutable page source shared by every context; later mutations of the original list are never observed. Usepaginate(Function)when elements differ per viewer or must be refreshable.Like the state factories, pagination declarations are legal only in field initializers or the constructor: the returned builder's
PaginationBuilder.build()registers the token and throwsIllegalStateExceptiononce registration froze the token table.- Type Parameters:
T- the element type- Parameters:
source- the elements to paginate, copied defensively- Returns:
- the pagination declaration builder
-
paginate
protected final <T> PaginationBuilder<T> paginate(@NotNull @NotNull Function<ViewContext, List<T>> source) Declares paginated rendering over a per-context element list: the function runs once per context at pagination initialization, on the main thread, and runs again for that context only whenPagination.refresh(context)is called.Like the state factories, pagination declarations are legal only in field initializers or the constructor: the returned builder's
PaginationBuilder.build()registers the token and throwsIllegalStateExceptiononce registration froze the token table.- Type Parameters:
T- the element type- Parameters:
source- the per-context element list factory; must not returnnull- Returns:
- the pagination declaration builder
-
paginateAsync
protected final <T> PaginationBuilder<T> paginateAsync(@NotNull @NotNull AsyncPageSupplier<T> source) Declares paginated rendering over an asynchronously loaded source: every context gets its own freshAsyncPageSourceat pagination initialization, so request ids, page caches, loading state and errors are never shared between viewers. The async-only builder options (loadingItem,onError,requestTimeout,cacheTtl,cacheMaxPages) are legal only on the builder returned here.Like the state factories, pagination declarations are legal only in field initializers or the constructor: the returned builder's
PaginationBuilder.build()registers the token and throwsIllegalStateExceptiononce registration froze the token table.- Type Parameters:
T- the element type- Parameters:
source- the page loader invoked per page request- Returns:
- the pagination declaration builder
-
paginateSource
protected final <T> PaginationBuilder<T> paginateSource(@NotNull @NotNull Function<ViewContext, PageSource<T>> factory) Escape hatch declaring paginated rendering over a customPageSource: the factory runs once per context at pagination initialization and must return the source instance serving exactly that context.Like the state factories, pagination declarations are legal only in field initializers or the constructor: the returned builder's
PaginationBuilder.build()registers the token and throwsIllegalStateExceptiononce registration froze the token table.- Type Parameters:
T- the element type- Parameters:
factory- the per-context page source factory; must not returnnull- Returns:
- the pagination declaration builder
-
tokenTable
Returns this view's token table; used by the engine to size per-session state storage and to freeze token registration. Plugin code must not call this method; it is reserved for the engine registration phase.- Returns:
- the token registry of this view instance
-