Interface ViewContext
- 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 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.@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 asopenView(Class), passing arguments to the target view.@NotNull org.bukkit.entity.Playerplayer()Returns the player viewing this session.@NotNull UUIDplayerId()Returns the unique id ofplayer().@NotNull org.bukkit.plugin.Pluginplugin()Returns the plugin that owns the inventory-api runtime.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 forplayer()when enabled by the view config, then legacy&color codes are translated.@NotNull Viewview()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
Returns the unique id ofplayer().- Returns:
- the viewer's UUID
-
view
Returns the view singleton this context belongs to.- Returns:
- the owning view instance
-
config
Returns the effective configuration of this session, with per-open overrides recorded inonOpenalready 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
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. insideonOpen) and after the session closed
-
isActive
boolean isActive()Returns whether this session is currently active (open, not transitioning or closed).- Returns:
truewhile the session is active
-
update
void update()Runs 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. -
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
Updates the container title in place (no reopen) via the title updater: placeholders are applied forplayer()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
Navigates 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.- 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 asopenView(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.- Parameters:
target- the registered view class to openarguments- the arguments handed to the target's contexts- Throws:
UnknownViewException- when the target class is not registered
-