Platform: TaskManager - Dani-error/velar GitHub Wiki
🕒 PlatformTaskManager
PlatformTaskManager
?
📘 What is PlatformTaskManager
provides a simple abstraction for scheduling tasks either synchronously or asynchronously on the underlying platform, with optional delayed execution based on server ticks.
🔧 Interface Overview
Method | Description |
---|---|
scheduleSync(task: Runnable) |
Schedule a task to run synchronously immediately. |
scheduleDelayedSync(delayTicks: Int, task: Runnable) |
Schedule a synchronous task with a delay (in ticks). |
scheduleAsync(task: Runnable) |
Schedule a task to run asynchronously immediately. |
scheduleDelayedAsync(delayTicks: Int, task: Runnable) |
Schedule an asynchronous task with a delay (in ticks). |
🏗️ Default Implementations
Async-based (used by Folia)
AsyncPlatformTaskManager
uses Java's ExecutorService
and ScheduledExecutorService
to handle async and delayed tasks off the main thread:
val taskManager = AsyncPlatformTaskManager.taskManager("my-extension")
taskManager.scheduleAsync { println("async task") }
taskManager.scheduleDelayedSync(20) { println("delayed sync task") }
Details: AsyncPlatformTaskManager.kt
Bukkit / Paper / Spigot
For Bukkit-based platforms, BukkitPlatformTaskManager
uses the native Bukkit scheduler:
val taskManager = BukkitPlatformTaskManager.taskManager(plugin)
taskManager.scheduleSync { /* sync code */ }
taskManager.scheduleDelayedAsync(10) { /* async delayed code */ }
Details: BukkitPlatformTaskManager.kt
📌 Usage Example
taskManager.scheduleSync {
println("Runs immediately on main thread")
}
taskManager.scheduleDelayedAsync(40) {
println("Runs async after 40 ticks delay")
}
You can implement your own
PlatformTaskManager
to adapt to different threading or scheduling models as needed for your platform.