Interface FoliaScheduler

All Known Implementing Classes:
BukkitFoliaScheduler

public interface FoliaScheduler
Thread-safe scheduler abstraction for Folia and non-Folia servers.

This interface provides methods to execute tasks on the appropriate threads:

  • Global region thread - for non-location-dependent operations
  • Region thread - for location-dependent operations
  • Entity scheduler - for entity-specific operations

Implementations handle the differences between Folia's threaded regions and traditional single-threaded Bukkit servers.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Represents a scheduled task that can be cancelled.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns true if the current thread is the primary server thread.
    void
    runAtEntity(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.entity.Entity entity, @NotNull Runnable task)
    Executes a task on the entity's scheduler.
    void
    runAtLocation(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.Location location, @NotNull Runnable task)
    Executes a task on the region thread for the given location.
    void
    runGlobal(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task)
    Executes a task on the global region thread.
    runGlobalDelayed(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delayTicks)
    Schedules a delayed task on the global region thread.
    runGlobalTimer(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Consumer<FoliaScheduler.ScheduledTask> task, long delayTicks, long periodTicks)
    Schedules a repeating task on the global region thread.
  • Method Details

    • runGlobal

      void runGlobal(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task)
      Executes a task on the global region thread.
      Parameters:
      plugin - the plugin scheduling the task
      task - the task to execute
    • runAtLocation

      void runAtLocation(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull Runnable task)
      Executes a task on the region thread for the given location.
      Parameters:
      plugin - the plugin scheduling the task
      location - the location determining which region thread
      task - the task to execute
    • runAtEntity

      void runAtEntity(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull org.bukkit.entity.Entity entity, @NotNull @NotNull Runnable task)
      Executes a task on the entity's scheduler.
      Parameters:
      plugin - the plugin scheduling the task
      entity - the entity to schedule the task for
      task - the task to execute
    • runGlobalDelayed

      @NotNull @NotNull FoliaScheduler.ScheduledTask runGlobalDelayed(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task, long delayTicks)
      Schedules a delayed task on the global region thread.
      Parameters:
      plugin - the plugin scheduling the task
      task - the task to execute
      delayTicks - the delay in ticks
      Returns:
      a task handle that can be used to cancel the task
    • runGlobalTimer

      @NotNull @NotNull FoliaScheduler.ScheduledTask runGlobalTimer(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Consumer<FoliaScheduler.ScheduledTask> task, long delayTicks, long periodTicks)
      Schedules a repeating task on the global region thread.
      Parameters:
      plugin - the plugin scheduling the task
      task - the task to execute
      delayTicks - the initial delay in ticks
      periodTicks - the period between executions in ticks
      Returns:
      a task handle that can be used to cancel the task
    • isPrimaryThread

      boolean isPrimaryThread()
      Returns true if the current thread is the primary server thread.
      Returns:
      true if on main thread