Class Scheduler
java.lang.Object
com.github.pinont.singularitylib.api.runnable.Scheduler
Platform-agnostic task scheduler facade. Picks Folia schedulers when running
under Folia and the Bukkit scheduler otherwise.
Tick semantics
Unless a method is explicitly named...Async with a TimeUnit
parameter, all delay and period values are interpreted as
server ticks (20 ticks = 1 second at normal rate) on both Paper and
Folia paths:
- Folia's
runAtFixedRatevariants take ticks natively. - The Bukkit scheduler's
runTaskTimertakes ticks natively.
TimeUnit: on Folia they are forwarded to AsyncScheduler
(which is time-based), on Paper they are converted to ticks via
Common.toTicks(long, TimeUnit) for runTaskTimer.-
Field Summary
FieldsModifier and TypeFieldDescriptionorg.bukkit.scheduler.BukkitTaskio.papermc.paper.threadedregions.scheduler.ScheduledTask -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcancelAllTasks(org.bukkit.plugin.Plugin plugin) Cancels every task owned by the plugin across all schedulers used by this class: on Paper the whole Bukkit scheduler; on Folia the async and global-region schedulers.voidCancels the single task started by this Scheduler instance, if any.io.papermc.paper.threadedregions.scheduler.AsyncSchedulerorg.bukkit.scheduler.BukkitSchedulerio.papermc.paper.threadedregions.scheduler.GlobalRegionSchedulerio.papermc.paper.threadedregions.scheduler.RegionSchedulergetTask()voidrunRepeatingTask(org.bukkit.plugin.Plugin plugin, org.bukkit.Location location, Runner runner, int delayTicks, long periodTicks, TimeUnit timeUnit) Runs a task repeatedly on the region owning the given location (Folia) or on the main thread (Paper).voidrunRepeatingTask(org.bukkit.plugin.Plugin plugin, org.bukkit.World world, Runner runner, int delayTicks, long periodTicks, TimeUnit timeUnit) Runs a task repeatedly in the given world (at its spawn chunk origin on Folia) or on the main thread (Paper).voidrunRepeatingTaskAsync(org.bukkit.plugin.Plugin plugin, Runner runner, int delay, long period, TimeUnit timeUnit) Runs a task repeatedly off the main thread / region threads.voidvoidrunTaskAsync(org.bukkit.plugin.Plugin plugin, Runner runner)
-
Field Details
-
scheduledTask
public io.papermc.paper.threadedregions.scheduler.ScheduledTask scheduledTask -
bukkitTask
public org.bukkit.scheduler.BukkitTask bukkitTask
-
-
Constructor Details
-
Scheduler
public Scheduler()
-
-
Method Details
-
getAsyncScheduler
public io.papermc.paper.threadedregions.scheduler.AsyncScheduler getAsyncScheduler() -
getBukkitScheduler
public org.bukkit.scheduler.BukkitScheduler getBukkitScheduler() -
getGlobalScheduler
public io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler getGlobalScheduler() -
getRegionScheduler
public io.papermc.paper.threadedregions.scheduler.RegionScheduler getRegionScheduler() -
getTask
-
runTaskAsync
-
runTask
-
runRepeatingTask
public void runRepeatingTask(org.bukkit.plugin.Plugin plugin, org.bukkit.Location location, Runner runner, int delayTicks, long periodTicks, TimeUnit timeUnit) Runs a task repeatedly on the region owning the given location (Folia) or on the main thread (Paper).- Parameters:
plugin- the plugin that owns the tasklocation- the location whose region executes the task (Folia only)runner- the task to rundelayTicks- initial delay in server ticks before the first runperiodTicks- period between runs in server tickstimeUnit- ignored: kept for source compatibility; both delay and period are always interpreted in ticks
-
runRepeatingTask
public void runRepeatingTask(org.bukkit.plugin.Plugin plugin, org.bukkit.World world, Runner runner, int delayTicks, long periodTicks, TimeUnit timeUnit) Runs a task repeatedly in the given world (at its spawn chunk origin on Folia) or on the main thread (Paper). See the class Javadoc for tick semantics.- Parameters:
plugin- the plugin that owns the taskworld- the world whose region executes the task (Folia only)runner- the task to rundelayTicks- initial delay in server ticksperiodTicks- period between runs in server tickstimeUnit- ignored: kept for source compatibility; ticks only
-
runRepeatingTaskAsync
public void runRepeatingTaskAsync(org.bukkit.plugin.Plugin plugin, Runner runner, int delay, long period, TimeUnit timeUnit) Runs a task repeatedly off the main thread / region threads. Here delay and period are interpreted in the suppliedTimeUniton both platforms: Folia's async scheduler is time-based natively, while the Paper path converts to ticks viaCommon.toTicks(long, TimeUnit).- Parameters:
plugin- the plugin that owns the taskrunner- the task to rundelay- initial delay before the first runperiod- period between runstimeUnit- unit ofdelayandperiod; must not be null
-
cancelTask
public void cancelTask()Cancels the single task started by this Scheduler instance, if any. -
cancelAllTasks
public void cancelAllTasks(org.bukkit.plugin.Plugin plugin) Cancels every task owned by the plugin across all schedulers used by this class: on Paper the whole Bukkit scheduler; on Folia the async and global-region schedulers. Region-scheduler tasks have no bulk cancel API in Folia/Paper 26.x — they must be cancelled individually through theirScheduledTaskhandles (seecancelTask()). Schedulers never touched by this instance are skipped via null guards.- Parameters:
plugin- the plugin whose tasks should be cancelled
-