Class FrameworkSlotContainer
java.lang.Object
com.ultikits.ultitools.ui.container.FrameworkSlotContainer
- All Implemented Interfaces:
SlotContainer
Thread-confined contents, contribution accounting and exactly-once disposition.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate List<org.bukkit.inventory.ItemStack> private List<org.bukkit.inventory.ItemStack> private @Nullable CompletionStage<EndOutcome> private final ContainerHostprivate final ContributionLedgerprivate static final UUIDprivate final BooleanSupplierprivate final UiOwnerprivate @Nullable FrameworkSlotContainer.PendingCommitprivate final FrameworkContainerRuntimeprivate longprivate final ContainerSpecprivate ContainerStateprivate @Nullable CompletionStage<CommitOutcome> private longprivate boolean -
Constructor Summary
ConstructorsConstructorDescriptionFrameworkSlotContainer(FrameworkContainerRuntime runtime, UiOwner owner, ContainerSpec spec, ContainerHost host, BooleanSupplier onContainerThread) -
Method Summary
Modifier and TypeMethodDescription(package private) voidprivate void(package private) booleanbelongsTo(FrameworkContainerRuntime candidate) (package private) voidchanged(ContainerChange change) changes()What changed since the baseline (the last load, initial contents or written commit).private List<org.bukkit.inventory.ItemStack> checkedContents(List<org.bukkit.inventory.ItemStack> next) (package private) voidprivate voidcommit()Writes the contents through the spec'sContainerStore: see the commit rules above.List<org.bukkit.inventory.ItemStack> contents()Copies of every index, lengthSlotContainer.size().(package private) TransferDecisiondecide(org.bukkit.entity.Player viewer, TransferKind kind, int index, org.bukkit.inventory.ItemStack item, int requested) (package private) voidList<org.bukkit.inventory.ItemStack> drain()Removes and returns every item; the container becomesENDEDand its disposition does not run.(package private) booleaneditable()end()Runs the disposition now; idempotent; the stage completes once the disposition has finished.private voidendAfterCommit(CompletableFuture<EndOutcome> result) private voidendNow(CompletableFuture<EndOutcome> result, EndOutcome outcome) private voidfinishCommit(FrameworkSlotContainer.PendingCommit work, StoreAnswer answer, boolean timeout) private voidfinishRefused(FrameworkSlotContainer.PendingCommit work, StoreAnswer.Refused refused) private voidfinishReturn(UUID player, List<org.bukkit.inventory.ItemStack> items, @Nullable Delivery delivery, @Nullable Throwable failure) private voidfinishUnknown(FrameworkSlotContainer.PendingCommit work, String message, @Nullable Throwable failure) org.bukkit.inventory.ItemStackget(int index) A copy of the item atindex;ItemStack.empty()if empty.booleanisViewed()Whether a session shows this container: the snapshot its backend was last given binds it, and that session has not been closed yet.kind()voidReplaces the contents with items that come from the module (for example read from storage), and makes them the new baseline; the ledger is cleared.private voidowner()(package private) voidprepareUnload(long deadline) (package private) voidrecord(org.bukkit.entity.Player viewer, TransferKind kind, org.bukkit.inventory.ItemStack item, int moved) private voidrecordAnswer(FrameworkSlotContainer.PendingCommit work, @Nullable StoreAnswer answer, @Nullable Throwable failure) (package private) voidredraw()(package private) voidreplace(int index, org.bukkit.inventory.ItemStack item) private voidprivate CompletableFuture<Void> returnBatch(UUID player, List<org.bukkit.inventory.ItemStack> items) private CompletionStage<Void> returnContributions(ContainerChanges changes) voidsetReadOnly(boolean readOnly) Puts the container into or out ofContainerState.READ_ONLY(for example while both traders have confirmed).intsize()private CompletionStage<CommitOutcome> (package private) voidstate()private voidundelivered(UUID player, List<org.bukkit.inventory.ItemStack> items) (package private) voidunload()(package private) void
-
Field Details
-
NIL
-
runtime
-
owner
-
spec
-
host
-
onContainerThread
-
ledger
-
viewers
-
contents
-
baseline
-
state
-
unloading
private boolean unloading -
unloadDeadline
private long unloadDeadline -
sequence
private long sequence -
pending
-
unloadCommit
-
ending
-
-
Constructor Details
-
FrameworkSlotContainer
FrameworkSlotContainer(FrameworkContainerRuntime runtime, UiOwner owner, ContainerSpec spec, ContainerHost host, BooleanSupplier onContainerThread)
-
-
Method Details
-
belongsTo
-
checkThread
void checkThread() -
requireMutable
private void requireMutable() -
owner
- Specified by:
ownerin interfaceSlotContainer
-
size
public int size()- Specified by:
sizein interfaceSlotContainer
-
kind
- Specified by:
kindin interfaceSlotContainer
-
state
- Specified by:
statein interfaceSlotContainer
-
get
public org.bukkit.inventory.ItemStack get(int index) Description copied from interface:SlotContainerA copy of the item atindex;ItemStack.empty()if empty.- Specified by:
getin interfaceSlotContainer
-
contents
Description copied from interface:SlotContainerCopies of every index, lengthSlotContainer.size().- Specified by:
contentsin interfaceSlotContainer
-
isViewed
public boolean isViewed()Description copied from interface:SlotContainerWhether a session shows this container: the snapshot its backend was last given binds it, and that session has not been closed yet.- Specified by:
isViewedin interfaceSlotContainer
-
changes
Description copied from interface:SlotContainerWhat changed since the baseline (the last load, initial contents or written commit).- Specified by:
changesin interfaceSlotContainer
-
setReadOnly
public void setReadOnly(boolean readOnly) Description copied from interface:SlotContainerPuts the container into or out ofContainerState.READ_ONLY(for example while both traders have confirmed). @throws IllegalStateException ifCOMMITTING,FAILEDorENDED- Specified by:
setReadOnlyin interfaceSlotContainer
-
load
Description copied from interface:SlotContainerReplaces 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 notSlotContainer.size()@throws IllegalStateException unlessEDITABLEorREAD_ONLY- Specified by:
loadin interfaceSlotContainer
-
checkedContents
-
attach
-
detach
-
editable
boolean editable() -
decide
TransferDecision decide(org.bukkit.entity.Player viewer, TransferKind kind, int index, org.bukkit.inventory.ItemStack item, int requested) -
replace
void replace(int index, org.bukkit.inventory.ItemStack item) -
record
void record(org.bukkit.entity.Player viewer, TransferKind kind, org.bukkit.inventory.ItemStack item, int moved) -
changed
-
redraw
void redraw() -
commit
Description copied from interface:SlotContainerWrites the contents through the spec'sContainerStore: 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.- Specified by:
commitin interfaceSlotContainer
-
startCommit
-
recordAnswer
private void recordAnswer(FrameworkSlotContainer.PendingCommit work, @Nullable @Nullable StoreAnswer answer, @Nullable @Nullable Throwable failure) -
onThread
-
finishCommit
private void finishCommit(FrameworkSlotContainer.PendingCommit work, StoreAnswer answer, boolean timeout) -
finishUnknown
private void finishUnknown(FrameworkSlotContainer.PendingCommit work, String message, @Nullable @Nullable Throwable failure) -
finishRefused
-
drain
Description copied from interface:SlotContainerRemoves and returns every item; the container becomesENDEDand its disposition does not run. The caller now owns the returned items (for example to hand a trade offer to the other player).- Specified by:
drainin interfaceSlotContainer
-
end
Description copied from interface:SlotContainerRuns the disposition now; idempotent; the stage completes once the disposition has finished.- Specified by:
endin interfaceSlotContainer
-
endAfterCommit
-
endNow
-
clearAndEnd
private void clearAndEnd() -
prepareUnload
void prepareUnload(long deadline) -
startUnloadCommit
void startUnloadCommit() -
unload
void unload() -
awaitAnswer
-
returnContributions
-
returnBatch
private CompletableFuture<Void> returnBatch(UUID player, List<org.bukkit.inventory.ItemStack> items) -
finishReturn
-
undelivered
-
warn
-