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 ClassesModifier and TypeInterfaceDescriptionstatic interfaceRepresents a scheduled task that can be cancelled. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true if the current thread is the primary server thread.voidrunAtEntity(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.entity.Entity entity, @NotNull Runnable task) Executes a task on the entity's scheduler.voidrunAtLocation(@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.voidExecutes a task on the global region thread.@NotNull FoliaScheduler.ScheduledTaskrunGlobalDelayed(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delayTicks) Schedules a delayed task on the global region thread.@NotNull FoliaScheduler.ScheduledTaskrunGlobalTimer(@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
Executes a task on the global region thread.- Parameters:
plugin- the plugin scheduling the tasktask- 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 tasklocation- the location determining which region threadtask- 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 taskentity- the entity to schedule the task fortask- 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 tasktask- the task to executedelayTicks- 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 tasktask- the task to executedelayTicks- the initial delay in ticksperiodTicks- 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
-