Interface SlotContainer

All Known Implementing Classes:
FrameworkSlotContainer

@NonExtendable public interface SlotContainer
Items that one or more framework screens show and edit. Owned by the module whose UiService created it; outlives any screen. Not thread-safe: confined to its thread (on Paper, the main thread); every method except owner(), size() and kind() throws IllegalStateException when called from another thread. owner(), size() and kind() never change and may be called from any thread, so a Grid that binds a container can be built on any thread.

Conservation: in a storage container, items enter only from a viewer's cursor or inventory, from load(List) or from ContainerSpec.Builder.initial, and leave only to a viewer's cursor or inventory, through drain(), or through the disposition. A template container holds copies: no real item ever enters or leaves.

For a remote backpack, use a storage container with a baseline, a conditional store, COMMIT and an undelivered handler. Bind visible indexes and page by changing bindings; a refused save returns put-ins, never reclaims take-outs. A trade uses RETURN_TO_CONTRIBUTORS and endWhenUnviewed(false), binds each trader's own offer EDITABLE and the other offer VIEW, freezes both after confirmation, and drains both on completion. Cancellation calls end(). A kit editor uses template(size).baseline(kitItems) and reads contents() to save definitions. Mail attachments use RETURN_TO_CONTRIBUTORS and drain() on confirmation.

Commit answers: Written moves the baseline and clears the ledger; Refused loads the store's current contents and returns net put-ins; Unknown, an exceptional stage or timeout leaves the container FAILED permanently, refunds nothing and transfers responsibility to the store. A concurrent commit returns the in-flight stage, and a container with no put-ins or take-outs does not call the store. Answers after the timeout are ignored and logged. The result is completed on the container's thread.

End runs once, on explicit end(), the last completed viewer close when endWhenUnviewed is true, or owner unload. RETURN_TO_CONTRIBUTORS returns remaining net put-ins in ledger order, reducing a taking player's own contributions first, then other contributors, then the baseline. Unattributed baseline items go to the handler under the nil UUID. COMMIT ends after the commit outcome; Unknown keeps items with the store. drain() ends without a disposition. Templates discard their copies. After end the container is not viewed and cannot be shown again. Showing or updating to a grid that binds an ended container throws IllegalStateException when called on the container's thread; if the container ends after that call and before the screen gets the snapshot, its bound slots show nothing and refuse every gesture. In-memory contents are not crash-journalled; modules needing crash safety must persist them.

Owner unload (a module reload or the server stopping) ends every container of the owner before the unload returns, on the unloading thread. It first runs the owner's pending deliveries, then starts the write of every COMMIT container that has put-ins or take-outs, and only then waits: each in-flight write is awaited for at most its commit timeout or 10 seconds after the unload began, whichever comes first, and its real answer is applied on the unloading thread (Written: committed; Refused: put-ins returned at once; otherwise the items stay with the store). RETURN_TO_CONTRIBUTORS deliveries made during the unload run at once (see UiService.deliver(Player, List)).

Known limitations. A transfer policy that calls this container's mutators is not supported (see TransferPolicy). Amounts in baseline, initial, load(List) and a Refused answer's contents are taken as given, even above an item's max stack size; they are the module's data. Under RETURN_TO_CONTRIBUTORS with a baseline, a viewer who takes out a baseline item consumes other contributors' credit before the baseline (ledger order), so that contributor's matching items may go to the undelivered handler under the nil UUID instead of back to them. In-memory contents are not crash-journalled.

  • Method Summary

    Modifier and Type
    Method
    Description
    What changed since the baseline (the last load, initial contents or written commit).
    Writes the contents through the spec's ContainerStore: see the commit rules above.
    List<org.bukkit.inventory.ItemStack>
    Copies of every index, length size().
    List<org.bukkit.inventory.ItemStack>
    Removes and returns every item; the container becomes ENDED and its disposition does not run.
    end()
    Runs the disposition now; idempotent; the stage completes once the disposition has finished.
    org.bukkit.inventory.ItemStack
    get(int index)
    A copy of the item at index; ItemStack.empty() if empty.
    boolean
    Whether a session shows this container: the snapshot its backend was last given binds it, and that session has not been closed yet.
     
    void
    load(List<org.bukkit.inventory.ItemStack> contents)
    Replaces the contents with items that come from the module (for example read from storage), and makes them the new baseline; the ledger is cleared.
     
    void
    setReadOnly(boolean readOnly)
    Puts the container into or out of ContainerState.READ_ONLY (for example while both traders have confirmed).
    int
     
     
  • Method Details

    • owner

      String owner()
    • size

      int size()
    • kind

    • state

    • get

      org.bukkit.inventory.ItemStack get(int index)
      A copy of the item at index; ItemStack.empty() if empty.
    • contents

      List<org.bukkit.inventory.ItemStack> contents()
      Copies of every index, length size().
    • isViewed

      boolean isViewed()
      Whether a session shows this container: the snapshot its backend was last given binds it, and that session has not been closed yet.
    • setReadOnly

      void setReadOnly(boolean readOnly)
      Puts the container into or out of ContainerState.READ_ONLY (for example while both traders have confirmed). @throws IllegalStateException if COMMITTING, FAILED or ENDED
    • load

      void load(List<org.bukkit.inventory.ItemStack> contents)
      Replaces the contents with items that come from the module (for example read from storage), and makes them the new baseline; the ledger is cleared. Items previously held are discarded, so call this only when the previous contents are stored elsewhere. @throws IllegalArgumentException if the list length is not size() @throws IllegalStateException unless EDITABLE or READ_ONLY
    • changes

      ContainerChanges changes()
      What changed since the baseline (the last load, initial contents or written commit).
    • commit

      Writes the contents through the spec's ContainerStore: see the commit rules above. Returns the in-flight stage if a commit is already running. Completes on this container's thread. Moving an item from one index of the container to another counts as a take-out and a put-in, so it is written.
      Throws:
      IllegalStateException - if the disposition is not COMMIT (no store), or the container is FAILED or ENDED
    • drain

      List<org.bukkit.inventory.ItemStack> drain()
      Removes and returns every item; the container becomes ENDED and its disposition does not run. The caller now owns the returned items (for example to hand a trade offer to the other player).
      Throws:
      IllegalStateException - unless EDITABLE or READ_ONLY
    • end

      Runs the disposition now; idempotent; the stage completes once the disposition has finished.