Interface UiService

All Known Implementing Classes:
RuntimeUiService

@NonExtendable public interface UiService
Shows intents. The instance a module receives by injection is owned by that module. May be called from any thread.

A player has at most one open session. When an intent opens for a player who has one, the previous session ends with CloseReason.REPLACED and its screen is closed before the new one opens. An intent that no backend supports ends with CloseReason.UNSUPPORTED, opens nothing and leaves the previous session open.

show to a viewer who is offline returns a session that is already not open, with Closed(DISCONNECTED) chosen; its result completes in a task of the global context. A viewer who quits ends the session with CloseReason.DISCONNECTED.

Both backends first close the player's own backpack menu if its cursor or crafting inputs are nonempty, letting vanilla return items to storage or drop overflow. Empty backpacks receive no extra close. A rejected first chest open or title reopen ends with CloseReason.INTERRUPTED; its container bindings are released through the normal close/commit path. A quit still selects DISCONNECTED.

A shown Dialog ends with CloseReason.INTERRUPTED if the player dies, changes worlds, or another inventory opens. Other plugins' dialogs have no server-side replacement signal, so undetectable interruptions still rely on ShowOptions.timeout(); give long-lived dialogs a suitable timeout.

Unloading the owning module ends every session of that owner that has not completed: before the unload returns, on the unloading thread, each screen is closed and each result completed, with Closed(OWNER_UNLOADED) or with the outcome already chosen if there was one. Stopping the server unloads every module, so no session is left incomplete. show while or after the owner unloads returns a session whose result is already Closed(OWNER_UNLOADED) and opens nothing.

  • Method Summary

    Modifier and Type
    Method
    Description
    A new container owned by this module.
    deliver(org.bukkit.entity.Player player, List<org.bukkit.inventory.ItemStack> items)
    Gives items to player: into the storage slots of their inventory (never armour or off-hand), the rest dropped at their feet.
    Owning module's name, for diagnostics.
    show(org.bukkit.entity.Player viewer, Grid grid)
    Shows a grid with intent-dependent defaults.
    show(org.bukkit.entity.Player viewer, Grid grid, ShowOptions options)
    Shows a grid with explicit options.
    <R> UiSession<R>
    show(org.bukkit.entity.Player viewer, UiIntent<R> intent)
    Shows an intent with intent-dependent defaults.
    <R> UiSession<R>
    show(org.bukkit.entity.Player viewer, UiIntent<R> intent, ShowOptions options)
    Shows an intent with explicit options.
  • Method Details

    • owner

      String owner()
      Owning module's name, for diagnostics.
    • show

      <R> UiSession<R> show(org.bukkit.entity.Player viewer, UiIntent<R> intent)
      Shows an intent with intent-dependent defaults.
    • show

      <R> UiSession<R> show(org.bukkit.entity.Player viewer, UiIntent<R> intent, ShowOptions options)
      Shows an intent with explicit options.
    • show

      GridSession show(org.bukkit.entity.Player viewer, Grid grid)
      Shows a grid with intent-dependent defaults.
    • show

      GridSession show(org.bukkit.entity.Player viewer, Grid grid, ShowOptions options)
      Shows a grid with explicit options.
    • container

      SlotContainer container(ContainerSpec spec)
      A new container owned by this module. Call on the server thread (the container's thread).
      Throws:
      IllegalStateException - if called off that thread, or while or after the owner unloads
    • deliver

      CompletionStage<Delivery> deliver(org.bukkit.entity.Player player, List<org.bukkit.inventory.ItemStack> items)
      Gives items to player: into the storage slots of their inventory (never armour or off-hand), the rest dropped at their feet. Runs in a task of the player's entity context; if that task cannot run because the player has quit, or the player is offline when it runs, nothing is given and every item not yet given is in Delivery.undelivered(). During the owner's unload, a call on the unloading thread gives at once, before it returns; a call from another thread during the unload, or any call after it, gives nothing and returns a stage already completed with every item undelivered. The stage always completes normally, exactly once. May be called from any thread.