runTaskLater
Schedules a task to run after a specified delay on the main server thread.
This extension function provides a simplified way to schedule delayed tasks without manually creating BukkitRunnable instances. The delay is specified in seconds and automatically converted to Minecraft ticks (20 ticks = 1 second).
The task executes exactly once after the delay period has elapsed. All code within the task lambda runs synchronously on the main server thread, making it safe to interact with the Bukkit API and modify game state.
Usage Example
class MyPlugin : JavaPlugin() {
override fun onEnable() {
// Send a message after 5 seconds
runTaskLater(5.0) {
server.broadcastMessage("5 seconds have passed!")
}
// Teleport player after 3.5 seconds with cancellation support
val task = runTaskLater(3.5) {
player.teleport(spawnLocation)
player.sendMessage("Teleported!")
}
// Can cancel the task before it runs
// task.cancel()
}
}Tick Conversion
The delay parameter is in seconds and converted to ticks using the formula:
Ticks = seconds × 20
Example: 1.0 second = 20 ticks
Example: 0.5 seconds = 10 ticks
Example: 2.5 seconds = 50 ticks
Important Notes
The task runs synchronously on the main server thread
Minimum practical delay is 0.05 seconds (1 tick)
Fractional ticks are truncated (e.g., 1.51 seconds = 30 ticks)
The task has access to BukkitRunnable methods (e.g., cancel(), isCancelled())
If the plugin is disabled before the task runs, the task is automatically cancelled
For repeating tasks, use runTaskTimer() instead
Thread Safety
Since this runs on the main thread, it's safe to:
Modify blocks, entities, and inventory
Send messages to players
Interact with any Bukkit/Paper API
For asynchronous operations, consider using Bukkit's async scheduler methods instead.
Receiver
Plugin The plugin that owns this scheduled task. Used for lifecycle management.
Return
BukkitTask A task object that can be used to cancel the scheduled execution or check its status.
Parameters
The delay before execution in seconds. Must be non-negative. Converted to ticks by multiplying by 20.
A lambda function containing the code to execute after the delay. Receives BukkitRunnable as receiver, allowing access to scheduling methods.