All Known Subinterfaces:
CloseContext, OpenContext, RenderContext, SlotClickContext, UpdateContext
All Known Implementing Classes:
AbstractViewContext, CloseContextImpl, OpenContextImpl, PlainViewContextImpl, RenderContextImpl, SlotClickContextImpl, UpdateContextImpl

@NonExtendable public interface ViewContext
Base contract shared by every per-phase context handed to View lifecycle handlers.

A context is bound to one (player, open) session. The mutating methods (update(), close(), updateTitle(String), openView(Class)) are main-thread only and throw IllegalStateException when invoked off-main.

  • 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.
    @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 openView(Class), passing arguments to the target view.
    @NotNull org.bukkit.entity.Player
    Returns the player viewing this session.
    @NotNull UUID
    Returns the unique id of player().
    @NotNull org.bukkit.plugin.Plugin
    Returns the plugin that owns the inventory-api runtime.
    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 player() when enabled by the view config, then legacy & color codes are translated.
    @NotNull View
    Returns the view singleton this context belongs to.
  • Method Details

    • player

      @NotNull @NotNull org.bukkit.entity.Player player()
      Returns the player viewing this session.
      Returns:
      the viewer
    • playerId

      @NotNull @NotNull UUID playerId()
      Returns the unique id of player().
      Returns:
      the viewer's UUID
    • view

      @NotNull @NotNull View view()
      Returns the view singleton this context belongs to.
      Returns:
      the owning view instance
    • config

      @NotNull @NotNull ViewConfig config()
      Returns the effective configuration of this session, with per-open overrides recorded in onOpen already applied.
      Returns:
      the effective, immutable view config
    • plugin

      @NotNull @NotNull org.bukkit.plugin.Plugin plugin()
      Returns the plugin that owns the inventory-api runtime.
      Returns:
      the owning plugin
    • arguments

      @NotNull @NotNull ViewArguments arguments()
      Returns the arguments this session was opened with; empty when none were passed.
      Returns:
      the open arguments
    • inventory

      @NotNull @NotNull org.bukkit.inventory.Inventory inventory()
      Returns the top container of this session.
      Returns:
      the Bukkit inventory backing this view
      Throws:
      IllegalStateException - before the container is created (e.g. inside onOpen) and after the session closed
    • isActive

      boolean isActive()
      Returns whether this session is currently active (open, not transitioning or closed).
      Returns:
      true while the session is active
    • update

      void update()
      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.
    • close

      void close()
      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.
    • updateTitle

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

      void openView(@NotNull @NotNull Class<? extends View> target)
      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.
      Parameters:
      target - the registered view class to open
      Throws:
      UnknownViewException - when the target class is not registered
    • openView

      void openView(@NotNull @NotNull Class<? extends View> target, @NotNull @NotNull ViewArguments arguments)
      Same as 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.
      Parameters:
      target - the registered view class to open
      arguments - the arguments handed to the target's contexts
      Throws:
      UnknownViewException - when the target class is not registered