Class AbstractViewContext
java.lang.Object
tech.guilhermekaua.spigotboot.inventoryapi.internal.context.AbstractViewContext
- All Implemented Interfaces:
ViewContext,StateBackedContext
- Direct Known Subclasses:
CloseContextImpl,OpenContextImpl,PlainViewContextImpl,RenderContextImpl,SlotClickContextImpl,UpdateContextImpl
@Internal
public abstract class AbstractViewContext
extends Object
implements ViewContext, StateBackedContext
Base implementation shared by every per-phase context: resolves all
ViewContext
accessors from the bound session and routes the mutating operations through the engine.
Implements the StateBackedContext seam so state tokens resolve their storage
without casting to concrete context classes.
Deferral policy (ยง5.4): close() and openView(java.lang.Class<? extends tech.guilhermekaua.spigotboot.inventoryapi.View>) are deferred to the end
of the tick during click dispatch, and openView(java.lang.Class<? extends tech.guilhermekaua.spigotboot.inventoryapi.View>) additionally while the session is
not yet active (opening/rendering); update() is never deferred because an update
pass is safe mid-click.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractViewContext(@NotNull ViewSession session, @NotNull ViewEngine engine) Binds the context to one session and the engine. -
Method Summary
Modifier and TypeMethodDescription@NotNull ViewArgumentsReturns the arguments this session was opened with; empty when none were passed.voidclose()Closes this session.@NotNull ViewConfigconfig()Returns the effective configuration of this session, with per-open overrides recorded inonOpenalready applied.booleanReturns whether this context may still access state;falseonce closed.protected @NotNull ViewEngineengine()Returns the engine this context routes operations through.@NotNull org.bukkit.inventory.InventoryReturns the top container of this session.booleanisActive()Returns whether this session is currently active (open, not transitioning or closed).voidNavigates to another registered view: this session closes withCloseReason.REPLACED, then the target opens.voidopenView(@NotNull Class<? extends View> target, @NotNull ViewArguments arguments) Same asViewContext.openView(Class), passing arguments to the target view.@NotNull Viewowner()Returns the view singleton owning this context, used for foreign-token checks.@NotNull org.bukkit.entity.Playerplayer()Returns the player viewing this session.@NotNull UUIDplayerId()Returns the unique id ofViewContext.player().@NotNull org.bukkit.plugin.Pluginplugin()Returns the plugin that owns the inventory-api runtime.@NotNull ViewSessionsession()Returns the session this context is bound to.@NotNull StateStoreReturns the per-session state storage backing this context.voidupdate()Runs a full update pass (UpdateTrigger.EXPLICIT) synchronously:onUpdatefollowed by a component repaint.voidupdateTitle(@NotNull String title) Updates the container title in place (no reopen) via the title updater: placeholders are applied forViewContext.player()when enabled by the view config, then legacy&color codes are translated.@NotNull Viewview()Returns the view singleton this context belongs to.
-
Constructor Details
-
AbstractViewContext
protected AbstractViewContext(@NotNull @NotNull ViewSession session, @NotNull @NotNull ViewEngine engine) Binds the context to one session and the engine.- Parameters:
session- the session this context belongs toengine- the engine executing lifecycle operations
-
-
Method Details
-
session
Returns the session this context is bound to.- Returns:
- the backing session
-
engine
Returns the engine this context routes operations through.- Returns:
- the view engine
-
player
@NotNull public @NotNull org.bukkit.entity.Player player()Description copied from interface:ViewContextReturns the player viewing this session.- Specified by:
playerin interfaceViewContext- Returns:
- the viewer
-
playerId
Description copied from interface:ViewContextReturns the unique id ofViewContext.player().- Specified by:
playerIdin interfaceViewContext- Returns:
- the viewer's UUID
-
view
Description copied from interface:ViewContextReturns the view singleton this context belongs to.- Specified by:
viewin interfaceViewContext- Returns:
- the owning view instance
-
config
Description copied from interface:ViewContextReturns the effective configuration of this session, with per-open overrides recorded inonOpenalready applied.- Specified by:
configin interfaceViewContext- Returns:
- the effective, immutable view config
-
plugin
@NotNull public @NotNull org.bukkit.plugin.Plugin plugin()Description copied from interface:ViewContextReturns the plugin that owns the inventory-api runtime.- Specified by:
pluginin interfaceViewContext- Returns:
- the owning plugin
-
arguments
Description copied from interface:ViewContextReturns the arguments this session was opened with; empty when none were passed.- Specified by:
argumentsin interfaceViewContext- Returns:
- the open arguments
-
inventory
@NotNull public @NotNull org.bukkit.inventory.Inventory inventory()Description copied from interface:ViewContextReturns the top container of this session.- Specified by:
inventoryin interfaceViewContext- Returns:
- the Bukkit inventory backing this view
-
isActive
public boolean isActive()Description copied from interface:ViewContextReturns whether this session is currently active (open, not transitioning or closed).- Specified by:
isActivein interfaceViewContext- Returns:
truewhile the session is active
-
update
public void update()Description copied from interface:ViewContextRuns a full update pass (UpdateTrigger.EXPLICIT) synchronously:onUpdatefollowed by a component repaint. State written during the pass is coalesced into a single trailing flush. Main thread only.- Specified by:
updatein interfaceViewContext
-
close
public void close()Description copied from interface:ViewContextCloses this session. When called during click dispatch the close is deferred to the end of the current tick and further clicks are swallowed. Outside click dispatch, the session closes synchronously before this method returns. Main thread only.- Specified by:
closein interfaceViewContext
-
updateTitle
Description copied from interface:ViewContextUpdates the container title in place (no reopen) via the title updater: placeholders are applied forViewContext.player()when enabled by the view config, then legacy&color codes are translated. Main thread only.- Specified by:
updateTitlein interfaceViewContext- Parameters:
title- the new title, legacy color codes supported
-
openView
Description copied from interface:ViewContextNavigates to another registered view: this session closes withCloseReason.REPLACED, then the target opens. Deferred to the end of the tick during click dispatch, or while the session is not yet active (opening/rendering). Calling this method from withinonCloseis illegal; the call is logged SEVERE and dropped to prevent navigation loops. Main thread only.- Specified by:
openViewin interfaceViewContext- Parameters:
target- the registered view class to open
-
openView
public void openView(@NotNull @NotNull Class<? extends View> target, @NotNull @NotNull ViewArguments arguments) Description copied from interface:ViewContextSame asViewContext.openView(Class), passing arguments to the target view. Deferred to the end of the tick during click dispatch, or while the session is not yet active (opening/rendering). Calling this method from withinonCloseis illegal; the call is logged SEVERE and dropped to prevent navigation loops.- Specified by:
openViewin interfaceViewContext- Parameters:
target- the registered view class to openarguments- the arguments handed to the target's contexts
-
stateStore
Description copied from interface:StateBackedContextReturns the per-session state storage backing this context.- Specified by:
stateStorein interfaceStateBackedContext- Returns:
- the state store
-
owner
Description copied from interface:StateBackedContextReturns the view singleton owning this context, used for foreign-token checks.- Specified by:
ownerin interfaceStateBackedContext- Returns:
- the owning view
-
contextActive
public boolean contextActive()Description copied from interface:StateBackedContextReturns whether this context may still access state;falseonce closed.- Specified by:
contextActivein interfaceStateBackedContext- Returns:
truewhile state access is legal
-