java.lang.Object
tech.guilhermekaua.spigotboot.inventoryapi.service.ViewService

public final class ViewService extends Object
DI facade for opening and closing views. All methods must be called on the main thread.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates the service.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    close(@NotNull org.bukkit.entity.Player player)
    Closes the player's open view; no-op when none is open.
    contextOf(@NotNull org.bukkit.entity.Player player)
    Returns a live context for the player's open view, if any.
    void
    open(@NotNull org.bukkit.entity.Player player, @NotNull Class<? extends View> view)
    Opens a registered view for the player without arguments.
    void
    open(@NotNull org.bukkit.entity.Player player, @NotNull Class<? extends View> view, @NotNull ViewArguments arguments)
    Opens a registered view for the player with the given arguments.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ViewService

      public ViewService(ViewEngine engine, SessionRegistry sessions)
      Creates the service.
      Parameters:
      engine - the view engine executing lifecycle operations
      sessions - the per-player session registry
  • Method Details

    • open

      public void open(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull Class<? extends View> view)
      Opens a registered view for the player without arguments.
      Parameters:
      player - the viewer
      view - the registered view class
      Throws:
      UnknownViewException - if the view class is not registered
      IllegalStateException - if called off the main thread
    • open

      public void open(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull Class<? extends View> view, @NotNull @NotNull ViewArguments arguments)
      Opens a registered view for the player with the given arguments.
      Parameters:
      player - the viewer
      view - the registered view class
      arguments - the open arguments
      Throws:
      UnknownViewException - if the view class is not registered
      IllegalStateException - if called off the main thread
    • close

      public void close(@NotNull @NotNull org.bukkit.entity.Player player)
      Closes the player's open view; no-op when none is open.
      Parameters:
      player - the viewer whose view should close
      Throws:
      IllegalStateException - if called off the main thread
    • contextOf

      @NotNull public @NotNull Optional<ViewContext> contextOf(@NotNull @NotNull org.bukkit.entity.Player player)
      Returns a live context for the player's open view, if any.
      Parameters:
      player - the viewer to look up
      Returns:
      the live context, or empty when the player has no open view