Class ContainerSpec.Builder

java.lang.Object
com.ultikits.ultitools.ui.ContainerSpec.Builder
Enclosing class:
ContainerSpec

public static final class ContainerSpec.Builder extends Object
Reusable builder. The last initial/baseline selection wins.
  • Field Details

    • kind

      private final ContainerKind kind
    • size

      private final int size
    • policy

      private TransferPolicy policy
    • disposition

      @Nullable private @Nullable Disposition disposition
    • store

      @Nullable private @Nullable ContainerStore store
    • commitTimeout

      private Duration commitTimeout
    • undelivered

      @Nullable private @Nullable UndeliveredHandler undelivered
    • endWhenUnviewed

      private boolean endWhenUnviewed
    • onChange

      private Consumer<ContainerChange> onChange
    • contributor

      @Nullable private @Nullable UUID contributor
    • initial

      private List<org.bukkit.inventory.ItemStack> initial
    • baseline

      private List<org.bukkit.inventory.ItemStack> baseline
  • Constructor Details

  • Method Details

    • emptyContents

      private List<org.bukkit.inventory.ItemStack> emptyContents()
    • policy

    • disposition

      public ContainerSpec.Builder disposition(Disposition disposition)
      Required for storage; rejected for template.
    • store

      public ContainerSpec.Builder store(ContainerStore store)
      Required when the disposition is COMMIT; rejected otherwise. Enables SlotContainer.commit().
    • commitTimeout

      public ContainerSpec.Builder commitTimeout(Duration timeout)
      Default 30 s; positive, at most 10 minutes. A store answer later than this counts as Unknown.
    • undelivered

      public ContainerSpec.Builder undelivered(UndeliveredHandler handler)
      Required for storage (items owed to a player who cannot receive them).
    • endWhenUnviewed

      public ContainerSpec.Builder endWhenUnviewed(boolean end)
      Default true: the container ends as soon as no session shows it any more, whatever the reason: the last showing session closes (in that session's close step, after its screen closes and before its result completes), or GridSession.update(Grid) gives every showing session a snapshot that no longer binds it. Showing another grid that binds the same container hands it over without ending it; paging within the same container never ends it. Opening any intent that does not bind it (a Confirm, a Form, another grid) for its last viewer ends it, so a module that opens sub-screens over a container and comes back builds it with endWhenUnviewed(false) and calls SlotContainer.end() or SlotContainer.drain() itself. A container that was never shown does not end this way.
    • onChange

      public ContainerSpec.Builder onChange(Consumer<ContainerChange> listener)
      Called after each applied transfer, on the container's thread; exceptions are logged and swallowed.
    • initial

      public ContainerSpec.Builder initial(UUID contributor, List<org.bukkit.inventory.ItemStack> contents)
      Initial contents, counted as put in by contributor (the RETURN disposition gives them back to them). Storage only: a template rejects it at build().
    • baseline

      public ContainerSpec.Builder baseline(List<org.bukkit.inventory.ItemStack> contents)
      Initial contents that are the baseline (for example read from storage); not owed to anyone.
    • sizedCopy

      private List<org.bukkit.inventory.ItemStack> sizedCopy(List<org.bukkit.inventory.ItemStack> contents)
    • validate

      private void validate()
    • validateTemplate

      private void validateTemplate()
    • validateStorage

      private void validateStorage()
    • build

      public ContainerSpec build()
      Throws:
      IllegalArgumentException - on a missing required or a forbidden attribute: storage without a disposition or an undelivered handler, COMMIT without a store, a store with any other disposition, or a template with a disposition, a store, an undelivered handler or contributed initial contents