Class ViewEngine
java.lang.Object
tech.guilhermekaua.spigotboot.inventoryapi.internal.engine.ViewEngine
Orchestrator of the view lifecycle: composes the fixed-order phase handlers and is the
sole mutator of sessions. All entry points assert that the calling thread owns the viewer's region.
-
Constructor Summary
ConstructorsConstructorDescriptionViewEngine(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull ViewRegistry views, @NotNull SessionRegistry sessions, @NotNull SlotPainter painter, @NotNull TitleUpdater titleUpdater, @NotNull PlatformScheduler scheduler) Creates the engine and its phase handlers. -
Method Summary
Modifier and TypeMethodDescriptionvoidbukkitClose(@NotNull ViewSession session, @NotNull org.bukkit.event.inventory.InventoryCloseEvent event) Handles a Bukkit close event for a session, guarded by container identity: a close event for a previous container (fired synchronously while opening a new view) must not tear down the session of the view that is being opened.voidclick(@NotNull ViewSession session, @NotNull org.bukkit.event.inventory.InventoryClickEvent event) Routes a Bukkit click event into the session per the click policy.voidclickDispatch(boolean active) Marks the engine as inside or outside click dispatch; toggled byclick(tech.guilhermekaua.spigotboot.inventoryapi.internal.session.ViewSession, org.bukkit.event.inventory.InventoryClickEvent)around routing.voidclose(@NotNull ViewSession session, @NotNull CloseReason reason) Closes a session with the given reason; idempotent on already closed sessions.voiddefer(@NotNull ViewSession session, @NotNull Runnable op) Defers an operation to the end of the current tick.voiddrag(@NotNull ViewSession session, @NotNull org.bukkit.event.inventory.InventoryDragEvent event) Applies the drag policy of a session: whencancelOnDragis enabled, any drag touching the top container is cancelled (mirrors the 2.x listener behavior).voidflushDirty(@NotNull ViewSession session) Flushes dirty state tokens of a session: each pass drains the dirty set and runs a STATE_CHANGE update over the watchers; passes repeat while handlers re-dirty tokens, capped at 8 cascades per flush, after which the remaining dirty tokens are dropped with a WARNING.voidflushShared(@NotNull View owner) Runs a full STATE_CHANGE repaint pass on every active session of the given view; full-pass fallback — the wired hooks use the watcher-scoped overload.booleanReturns whether a click event is currently being dispatched (drives operation deferral).voidopen(@NotNull org.bukkit.entity.Player player, @NotNull Class<? extends View> viewType, @NotNull ViewArguments arguments) Opens a registered view for a player, replacing any previous session at the commit point (spec §7).voidpaginationSettle(@NotNull ViewSession session, int tokenId) Runs a pagination-settle update pass scoped to the settled token, then flushes any state the handlers dirtied.@NotNull SlotPainterpainter()Returns the slot painter used by the rendering phases; pagination bindings paint their page frames through it.@NotNull org.bukkit.plugin.Pluginplugin()Returns the plugin owning the inventory-api runtime.@NotNull PlatformSchedulerReturns the platform scheduler used by this engine.@NotNull TitleUpdaterReturns the in-place title update strategy.voidupdate(@NotNull ViewSession session, @NotNull UpdateTrigger trigger) Runs an update pass on a session, then flushes any state the handlers dirtied.voidupdateTitle(@NotNull ViewSession session, @NotNull String title) Updates the container title of a session in place: placeholders are applied for the session's player when the effective config enables them, then legacy&color codes are translated, and the result is handed to theTitleUpdater.
-
Constructor Details
-
ViewEngine
public ViewEngine(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull ViewRegistry views, @NotNull @NotNull SessionRegistry sessions, @NotNull @NotNull SlotPainter painter, @NotNull @NotNull TitleUpdater titleUpdater, @NotNull @NotNull PlatformScheduler scheduler) Creates the engine and its phase handlers.- Parameters:
plugin- the plugin owning the inventory-api runtimeviews- the view registrysessions- the per-player session registrypainter- the slot painter used by the rendering phasestitleUpdater- the in-place title update strategyscheduler- the platform scheduler
-
-
Method Details
-
open
public void open(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull Class<? extends View> viewType, @NotNull @NotNull ViewArguments arguments) Opens a registered view for a player, replacing any previous session at the commit point (spec §7). Self-defers to end of tick during click dispatch, so service-path opens made from a click handler never tear down the clicked session mid-dispatch; the registration check then runs when the deferred open executes.- Parameters:
player- the viewerviewType- the registered view classarguments- the open arguments- Throws:
UnknownViewException- when the view class is not registeredIllegalArgumentException- when aninitialStateargument has a mismatching typeIllegalStateException- when called off the thread owning the viewer's region
-
close
Closes a session with the given reason; idempotent on already closed sessions. Self-defers to end of tick during click dispatch, so service-path closes made from a click handler never tear down the clicked session mid-dispatch.- Parameters:
session- the session to closereason- the close reason
-
updateTitle
Updates the container title of a session in place: placeholders are applied for the session's player when the effective config enables them, then legacy&color codes are translated, and the result is handed to theTitleUpdater.- Parameters:
session- the session whose container title is updatedtitle- the new title, legacy color codes supported- Throws:
IllegalStateException- when called off the thread owning the viewer's region
-
update
Runs an update pass on a session, then flushes any state the handlers dirtied.- Parameters:
session- the session to updatetrigger- the cause of the update
-
paginationSettle
Runs a pagination-settle update pass scoped to the settled token, then flushes any state the handlers dirtied. ACTIVE and TRANSITIONING sessions receive the settle; CLOSED and OPENING sessions drop it entirely — no paint, no watcher marking, noonUpdate(§7).- Parameters:
session- the session whose pagination token settledtokenId- the token id of the settled pagination declaration- Throws:
IllegalStateException- when called off the thread owning the viewer's region
-
click
public void click(@NotNull @NotNull ViewSession session, @NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent event) Routes a Bukkit click event into the session per the click policy. Contextclose()/openView()calls and component post-actions made while this method runs are deferred to end of tick; dirty state written by handlers is flushed after dispatch completes.- Parameters:
session- the clicked sessionevent- the Bukkit event
-
drag
public void drag(@NotNull @NotNull ViewSession session, @NotNull @NotNull org.bukkit.event.inventory.InventoryDragEvent event) Applies the drag policy of a session: whencancelOnDragis enabled, any drag touching the top container is cancelled (mirrors the 2.x listener behavior).- Parameters:
session- the affected sessionevent- the Bukkit event
-
bukkitClose
public void bukkitClose(@NotNull @NotNull ViewSession session, @NotNull @NotNull org.bukkit.event.inventory.InventoryCloseEvent event) Handles a Bukkit close event for a session, guarded by container identity: a close event for a previous container (fired synchronously while opening a new view) must not tear down the session of the view that is being opened.- Parameters:
session- the player's sessionevent- the Bukkit event
-
flushDirty
Flushes dirty state tokens of a session: each pass drains the dirty set and runs a STATE_CHANGE update over the watchers; passes repeat while handlers re-dirty tokens, capped at 8 cascades per flush, after which the remaining dirty tokens are dropped with a WARNING.- Parameters:
session- the session to flush
-
defer
Defers an operation to the end of the current tick. The session leaves ACTIVE immediately (TRANSITIONING) so further clicks are swallowed until the operation runs; sessions still TRANSITIONING after the drain return to ACTIVE. Every queued operation is guarded so it no-ops when the session was closed before the tick ran (manual close, disconnect, plugin disable, or an earlier deferred operation queued by the same click).- Parameters:
session- the session the operation belongs toop- the operation to run at end of tick
-
isInClickDispatch
public boolean isInClickDispatch()Returns whether a click event is currently being dispatched (drives operation deferral).- Returns:
truewhile a click is being dispatched
-
clickDispatch
@Internal public void clickDispatch(boolean active) Marks the engine as inside or outside click dispatch; toggled byclick(tech.guilhermekaua.spigotboot.inventoryapi.internal.session.ViewSession, org.bukkit.event.inventory.InventoryClickEvent)around routing.- Parameters:
active-truewhile a click is being dispatched
-
painter
Returns the slot painter used by the rendering phases; pagination bindings paint their page frames through it.- Returns:
- the slot painter
-
plugin
@NotNull public @NotNull org.bukkit.plugin.Plugin plugin()Returns the plugin owning the inventory-api runtime.- Returns:
- the owning plugin
-
scheduler
Returns the platform scheduler used by this engine.- Returns:
- the platform scheduler
-
titleUpdater
Returns the in-place title update strategy.- Returns:
- the title updater
-