Interface PlatformScheduler

All Known Implementing Classes:
BukkitPlatformScheduler, FoliaPlatformScheduler

public interface PlatformScheduler
Platform-neutral scheduling. On Folia every task is bound to a region (an entity's, a location's, or the global region); on legacy Spigot/Paper all variants fall back to the single main thread. Obtain the configured instance by injecting this type.

Times are in server ticks (20 per second), matching the legacy scheduler.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    ownsRegion(@NotNull org.bukkit.entity.Entity entity)
     
    boolean
    ownsRegion(@NotNull org.bukkit.Location location)
     
    @NotNull PlatformTask
    runAtRegion(@NotNull org.bukkit.Location location, @NotNull Runnable task)
    Runs a task on the thread owning the given location's region (Folia) or the main thread (legacy).
    @NotNull PlatformTask
    runAtRegionLater(@NotNull org.bukkit.Location location, @NotNull Runnable task, long delayTicks)
    Runs a task on the thread owning the given location's region (Folia) or the main thread (legacy), after a delay.
    @NotNull PlatformTask
    runGlobal(@NotNull Runnable task)
    Runs a task on the global region thread (Folia) or the main thread (legacy).
    @NotNull PlatformTask
    runGlobalLater(@NotNull Runnable task, long delayTicks)
    Runs a task on the global region thread (Folia) or the main thread (legacy), after a delay.
    @NotNull PlatformTask
    runOnEntity(@NotNull org.bukkit.entity.Entity entity, @NotNull Runnable task, @Nullable Runnable retired)
    Runs a task on the thread owning the entity's region (Folia) or the main thread (legacy).
    @NotNull PlatformTask
    runOnEntityAtFixedRate(@NotNull org.bukkit.entity.Entity entity, @NotNull Runnable task, @Nullable Runnable retired, long delayTicks, long periodTicks)
    Runs a task repeatedly on the thread owning the entity's region (Folia) or the main thread (legacy).
    @NotNull PlatformTask
    runOnEntityLater(@NotNull org.bukkit.entity.Entity entity, @NotNull Runnable task, @Nullable Runnable retired, long delayTicks)
    Runs a task on the thread owning the entity's region (Folia) or the main thread (legacy), after a delay.
  • Method Details

    • runOnEntity

      @NotNull @NotNull PlatformTask runOnEntity(@NotNull @NotNull org.bukkit.entity.Entity entity, @NotNull @NotNull Runnable task, @Nullable @Nullable Runnable retired)
      Runs a task on the thread owning the entity's region (Folia) or the main thread (legacy).
      Parameters:
      entity - the entity whose region owns the task
      task - the work to run
      retired - run instead of task if the entity is removed before it fires (Folia only); ignored on legacy
      Returns:
      a cancellable handle
    • runOnEntityLater

      @NotNull @NotNull PlatformTask runOnEntityLater(@NotNull @NotNull org.bukkit.entity.Entity entity, @NotNull @NotNull Runnable task, @Nullable @Nullable Runnable retired, long delayTicks)
      Runs a task on the thread owning the entity's region (Folia) or the main thread (legacy), after a delay.
      Parameters:
      entity - the entity whose region owns the task
      task - the work to run
      retired - run instead of task if the entity is removed before it fires (Folia only); ignored on legacy
      delayTicks - delay in ticks before the task fires; clamped to at least 1
      Returns:
      a cancellable handle
    • runOnEntityAtFixedRate

      @NotNull @NotNull PlatformTask runOnEntityAtFixedRate(@NotNull @NotNull org.bukkit.entity.Entity entity, @NotNull @NotNull Runnable task, @Nullable @Nullable Runnable retired, long delayTicks, long periodTicks)
      Runs a task repeatedly on the thread owning the entity's region (Folia) or the main thread (legacy).
      Parameters:
      entity - the entity whose region owns the task
      task - the work to run each period
      retired - run instead of task if the entity is removed before it fires (Folia only); ignored on legacy
      delayTicks - delay in ticks before the first execution; clamped to at least 1
      periodTicks - interval in ticks between subsequent executions; clamped to at least 1
      Returns:
      a cancellable handle
    • runAtRegion

      @NotNull @NotNull PlatformTask runAtRegion(@NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull Runnable task)
      Runs a task on the thread owning the given location's region (Folia) or the main thread (legacy).
      Parameters:
      location - the location whose region owns the task
      task - the work to run
      Returns:
      a cancellable handle
    • runAtRegionLater

      @NotNull @NotNull PlatformTask runAtRegionLater(@NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull Runnable task, long delayTicks)
      Runs a task on the thread owning the given location's region (Folia) or the main thread (legacy), after a delay.
      Parameters:
      location - the location whose region owns the task
      task - the work to run
      delayTicks - delay in ticks before the task fires; clamped to at least 1
      Returns:
      a cancellable handle
    • runGlobal

      @NotNull @NotNull PlatformTask runGlobal(@NotNull @NotNull Runnable task)
      Runs a task on the global region thread (Folia) or the main thread (legacy).
      Parameters:
      task - the work to run
      Returns:
      a cancellable handle
    • runGlobalLater

      @NotNull @NotNull PlatformTask runGlobalLater(@NotNull @NotNull Runnable task, long delayTicks)
      Runs a task on the global region thread (Folia) or the main thread (legacy), after a delay.
      Parameters:
      task - the work to run
      delayTicks - delay in ticks before the task fires; clamped to at least 1
      Returns:
      a cancellable handle
    • ownsRegion

      boolean ownsRegion(@NotNull @NotNull org.bukkit.entity.Entity entity)
      Parameters:
      entity - the entity to check
      Returns:
      true if the current thread owns the entity's region (Folia) or is the main thread (legacy) — i.e. it is safe to touch the entity now.
    • ownsRegion

      boolean ownsRegion(@NotNull @NotNull org.bukkit.Location location)
      Parameters:
      location - the location to check
      Returns:
      true if the current thread owns the given location's region (Folia) or is the main thread (legacy) — i.e. it is safe to touch that location now.