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

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractViewContext(@NotNull ViewSession session, @NotNull ViewEngine engine)
    Binds the context to one session and the engine.
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull ViewArguments
    Returns the arguments this session was opened with; empty when none were passed.
    void
    Closes this session.
    @NotNull ViewConfig
    Returns the effective configuration of this session, with per-open overrides recorded in onOpen already applied.
    boolean
    Returns whether this context may still access state; false once closed.
    protected @NotNull ViewEngine
    Returns the engine this context routes operations through.
    @NotNull org.bukkit.inventory.Inventory
    Returns the top container of this session.
    boolean
    Returns whether this session is currently active (open, not transitioning or closed).
    void
    openView(@NotNull Class<? extends View> target)
    Navigates to another registered view: this session closes with CloseReason.REPLACED, then the target opens.
    void
    openView(@NotNull Class<? extends View> target, @NotNull ViewArguments arguments)
    Same as ViewContext.openView(Class), passing arguments to the target view.
    @NotNull View
    Returns the view singleton owning this context, used for foreign-token checks.
    @NotNull org.bukkit.entity.Player
    Returns the player viewing this session.
    @NotNull UUID
    Returns the unique id of ViewContext.player().
    @NotNull org.bukkit.plugin.Plugin
    Returns the plugin that owns the inventory-api runtime.
    @NotNull ViewSession
    Returns the session this context is bound to.
    @NotNull StateStore
    Returns the per-session state storage backing this context.
    void
    Runs a full update pass (UpdateTrigger.EXPLICIT) synchronously: onUpdate followed by a component repaint.
    void
    updateTitle(@NotNull String title)
    Updates the container title in place (no reopen) via the title updater: placeholders are applied for ViewContext.player() when enabled by the view config, then legacy & color codes are translated.
    @NotNull View
    Returns the view singleton this context belongs to.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 to
      engine - the engine executing lifecycle operations
  • Method Details

    • session

      @NotNull public @NotNull ViewSession session()
      Returns the session this context is bound to.
      Returns:
      the backing session
    • engine

      @NotNull protected @NotNull ViewEngine 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: ViewContext
      Returns the player viewing this session.
      Specified by:
      player in interface ViewContext
      Returns:
      the viewer
    • playerId

      @NotNull public @NotNull UUID playerId()
      Description copied from interface: ViewContext
      Returns the unique id of ViewContext.player().
      Specified by:
      playerId in interface ViewContext
      Returns:
      the viewer's UUID
    • view

      @NotNull public @NotNull View view()
      Description copied from interface: ViewContext
      Returns the view singleton this context belongs to.
      Specified by:
      view in interface ViewContext
      Returns:
      the owning view instance
    • config

      @NotNull public @NotNull ViewConfig config()
      Description copied from interface: ViewContext
      Returns the effective configuration of this session, with per-open overrides recorded in onOpen already applied.
      Specified by:
      config in interface ViewContext
      Returns:
      the effective, immutable view config
    • plugin

      @NotNull public @NotNull org.bukkit.plugin.Plugin plugin()
      Description copied from interface: ViewContext
      Returns the plugin that owns the inventory-api runtime.
      Specified by:
      plugin in interface ViewContext
      Returns:
      the owning plugin
    • arguments

      @NotNull public @NotNull ViewArguments arguments()
      Description copied from interface: ViewContext
      Returns the arguments this session was opened with; empty when none were passed.
      Specified by:
      arguments in interface ViewContext
      Returns:
      the open arguments
    • inventory

      @NotNull public @NotNull org.bukkit.inventory.Inventory inventory()
      Description copied from interface: ViewContext
      Returns the top container of this session.
      Specified by:
      inventory in interface ViewContext
      Returns:
      the Bukkit inventory backing this view
    • isActive

      public boolean isActive()
      Description copied from interface: ViewContext
      Returns whether this session is currently active (open, not transitioning or closed).
      Specified by:
      isActive in interface ViewContext
      Returns:
      true while the session is active
    • update

      public void update()
      Description copied from interface: ViewContext
      Runs a full update pass (UpdateTrigger.EXPLICIT) synchronously: onUpdate followed by a component repaint. State written during the pass is coalesced into a single trailing flush. Main thread only.
      Specified by:
      update in interface ViewContext
    • close

      public void close()
      Description copied from interface: ViewContext
      Closes 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:
      close in interface ViewContext
    • updateTitle

      public void updateTitle(@NotNull @NotNull String title)
      Description copied from interface: ViewContext
      Updates the container title in place (no reopen) via the title updater: placeholders are applied for ViewContext.player() when enabled by the view config, then legacy & color codes are translated. Main thread only.
      Specified by:
      updateTitle in interface ViewContext
      Parameters:
      title - the new title, legacy color codes supported
    • openView

      public void openView(@NotNull @NotNull Class<? extends View> target)
      Description copied from interface: ViewContext
      Navigates to another registered view: this session closes with CloseReason.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 within onClose is illegal; the call is logged SEVERE and dropped to prevent navigation loops. Main thread only.
      Specified by:
      openView in interface ViewContext
      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: ViewContext
      Same as ViewContext.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 within onClose is illegal; the call is logged SEVERE and dropped to prevent navigation loops.
      Specified by:
      openView in interface ViewContext
      Parameters:
      target - the registered view class to open
      arguments - the arguments handed to the target's contexts
    • stateStore

      @NotNull public @NotNull StateStore stateStore()
      Description copied from interface: StateBackedContext
      Returns the per-session state storage backing this context.
      Specified by:
      stateStore in interface StateBackedContext
      Returns:
      the state store
    • owner

      @NotNull public @NotNull View owner()
      Description copied from interface: StateBackedContext
      Returns the view singleton owning this context, used for foreign-token checks.
      Specified by:
      owner in interface StateBackedContext
      Returns:
      the owning view
    • contextActive

      public boolean contextActive()
      Description copied from interface: StateBackedContext
      Returns whether this context may still access state; false once closed.
      Specified by:
      contextActive in interface StateBackedContext
      Returns:
      true while state access is legal