Class Scheduler

java.lang.Object
com.github.pinont.singularitylib.api.runnable.Scheduler

public class Scheduler extends Object
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 runAtFixedRate variants take ticks natively.
  • The Bukkit scheduler's runTaskTimer takes ticks natively.
The async repeating variant interprets its delay/period in the supplied 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

    Fields
    Modifier and Type
    Field
    Description
    org.bukkit.scheduler.BukkitTask
     
    io.papermc.paper.threadedregions.scheduler.ScheduledTask
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    void
    Cancels the single task started by this Scheduler instance, if any.
    io.papermc.paper.threadedregions.scheduler.AsyncScheduler
     
    org.bukkit.scheduler.BukkitScheduler
     
    io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler
     
    io.papermc.paper.threadedregions.scheduler.RegionScheduler
     
     
    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).
    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).
    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.
    void
    runTask(org.bukkit.plugin.Plugin plugin, Runner runner)
     
    void
    runTaskAsync(org.bukkit.plugin.Plugin plugin, Runner runner)
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public Object getTask()
    • runTaskAsync

      public void runTaskAsync(org.bukkit.plugin.Plugin plugin, Runner runner)
    • runTask

      public void runTask(org.bukkit.plugin.Plugin plugin, Runner runner)
    • 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 task
      location - the location whose region executes the task (Folia only)
      runner - the task to run
      delayTicks - initial delay in server ticks before the first run
      periodTicks - period between runs in server ticks
      timeUnit - 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 task
      world - the world whose region executes the task (Folia only)
      runner - the task to run
      delayTicks - initial delay in server ticks
      periodTicks - period between runs in server ticks
      timeUnit - 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 supplied TimeUnit on both platforms: Folia's async scheduler is time-based natively, while the Paper path converts to ticks via Common.toTicks(long, TimeUnit).
      Parameters:
      plugin - the plugin that owns the task
      runner - the task to run
      delay - initial delay before the first run
      period - period between runs
      timeUnit - unit of delay and period; 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 their ScheduledTask handles (see cancelTask()). Schedulers never touched by this instance are skipped via null guards.
      Parameters:
      plugin - the plugin whose tasks should be cancelled