Scheduler
Bukkit's built-in scheduler is tedious at best, so Twilight takes advantage of beautiful Kotlin syntax to make it easier to write, as well as adding a custom TimeUnit to save you calculating ticks.
How to schedule a single task to run on Bukkit's main thread either sync or async:
sync {
println("I am a sync BukkitRunnable")
}
async {
println("I am an async BukkitRunnable")
}
How to schedule a delayed task, with optional custom time unit and async parameters:
// SYNC
delay {
println("I am a sync BukkitRunnable delayed by 1 tick")
}
delay(10) {
println("I am a sync BukkitRunnable delayed by 10 ticks")
}
delay(1, TimeUnit.SECONDS) {
println("I am a sync BukkitRunnable delayed by 1 second")
}
// ASYNC
delay(10, true) {
println("I am an async BukkitRunnable delayed by 10 ticks")
}
delay(1, TimeUnit.SECONDS, true) {
println("I am an async BukkitRunnable delayed by 1 second")
}
How to schedule a repeating task, with optional custom time unit and async parameters:
// SYNC
repeat(10) {
println("I am a sync BukkitRunnable running every 10 ticks")
}
repeat(10, TimeUnit.SECONDS) {
println("I am a sync BukkitRunnable running every 10 seconds")
}
repeat(5, 10) {
println("I am a sync BukkitRunnable running every 10 ticks, waiting 5 before starting")
}
repeat(5, 10, TimeUnit.SECONDS) {
println("I am a sync BukkitRunnable running every 10 seconds, waiting 5 before starting")
}
// ASYNC
repeat(10, true) {
println("I am an async BukkitRunnable running every 10 ticks")
}
repeat(10, TimeUnit.SECONDS, true) {
println("I am an async BukkitRunnable running every 10 seconds")
}
repeat(5, 10, true) {
println("I am an async BukkitRunnable running every 10 ticks, waiting 5 before starting")
}
repeat(5, 10, TimeUnit.SECONDS, true) {
println("I am an async BukkitRunnable running every 10 seconds, waiting 5 before starting")
}
Last modified: 21 February 2024