Class Context
java.lang.Object
com.ultikits.ultitools.scheduling.internal.Context
- All Implemented Interfaces:
TaskContext, Executor
Validates submissions and maps an affinity to one backend delivery.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Context.Affinityprivate final intprivate final intprivate final @Nullable org.bukkit.entity.Entity(package private) final OwnedSchedulerprivate final @Nullable org.bukkit.World -
Constructor Summary
ConstructorsConstructorDescriptionContext(OwnedScheduler owner, Context.Affinity affinity, @Nullable org.bukkit.World world, int chunkX, int chunkZ, @Nullable org.bukkit.entity.Entity entity) -
Method Summary
Modifier and TypeMethodDescriptionprivate long(package private) @Nullable io.papermc.paper.threadedregions.scheduler.ScheduledTaskdeliver(Consumer<io.papermc.paper.threadedregions.scheduler.ScheduledTask> task, Runnable retired, long delay) voidRuns the command throughTaskContext.run(Runnable), discarding its handle.booleanWhether the calling thread owns this context right now, whether or not it is running inside a task submitted through this API.Runs once, never inline, even on the context's own thread; on tick contexts, on the next tick.Runs once after a delay.runRepeating(Duration initialDelay, Duration period, Consumer<? super TaskHandle> task) Runs after the initial delay and then at the given period until cancelled, retired or unloaded.<T> CompletableFuture<T> Runstaskonce (asTaskContext.run(Runnable)) and completes the returned future with its result, or exceptionally with what it threw, without logging the failure while the future can still observe it.
-
Field Details
-
owner
-
affinity
-
world
@Nullable private final @Nullable org.bukkit.World world -
chunkX
private final int chunkX -
chunkZ
private final int chunkZ -
entity
@Nullable private final @Nullable org.bukkit.entity.Entity entity
-
-
Constructor Details
-
Context
Context(OwnedScheduler owner, Context.Affinity affinity, @Nullable @Nullable org.bukkit.World world, int chunkX, int chunkZ, @Nullable @Nullable org.bukkit.entity.Entity entity)
-
-
Method Details
-
run
Description copied from interface:TaskContextRuns once, never inline, even on the context's own thread; on tick contexts, on the next tick. A thrown failure is logged exactly once at WARNING with the owner's name and original throwable; the handle endsTaskState.FAILEDand its completion fails with that throwable.- Specified by:
runin interfaceTaskContext
-
runLater
Description copied from interface:TaskContextRuns once after a delay. Zero behaves asTaskContext.run(Runnable). Failure logging and exceptional completion are the same as forrun.- Specified by:
runLaterin interfaceTaskContext
-
runRepeating
public TaskHandle runRepeating(Duration initialDelay, Duration period, Consumer<? super TaskHandle> task) Description copied from interface:TaskContextRuns after the initial delay and then at the given period until cancelled, retired or unloaded. The consumer receives its own handle and may cancel itself. An exception from one execution is logged with the owner's name and does not stop repetition.- Specified by:
runRepeatingin interfaceTaskContext
-
supply
Description copied from interface:TaskContextRunstaskonce (asTaskContext.run(Runnable)) and completes the returned future with its result, or exceptionally with what it threw, without logging the failure while the future can still observe it. The future followsCompletableFuturerules: cancelling it before it completes always succeeds. If the task has not started it then never runs; if it has started it finishes, its result is discarded, and an exception it throws is logged once as a WARNING with the owner's name, because no caller can observe it any more. An entity removed before the start completes the future withTaskRetiredException.- Specified by:
supplyin interfaceTaskContext
-
execute
Description copied from interface:TaskContextRuns the command throughTaskContext.run(Runnable), discarding its handle. A thrown failure is logged exactly once at WARNING with the owner's name and original throwable.- Specified by:
executein interfaceExecutor- Specified by:
executein interfaceTaskContext
-
isCurrentThread
public boolean isCurrentThread()Description copied from interface:TaskContextWhether the calling thread owns this context right now, whether or not it is running inside a task submitted through this API.On Paper every tick context (global, every region, every entity) is owned by the server main thread, so code on the main thread (an event listener, a command, a task) gets
trueand every other thread getsfalse. Under Folia the answer follows region ownership. The async context is owned by no thread and always answersfalse; to check that the caller is off the tick threads use!scheduler.global().isCurrentThread(). For an entity that is already removed the answer is unspecified.- Specified by:
isCurrentThreadin interfaceTaskContext
-
deliver
-
convert
-