Pages: Tasks & scheduling

Tasks & scheduling

Tasks is a simple wrapper around Bukkit's scheduler, so you don't need to pass your plugin instance around everywhere.

Tasks.run { /* runs next tick */ }
Tasks.runAsync { /* runs off the main thread */ }
Tasks.runLater(20) { /* runs in 1 second */ }
Tasks.runTimer(0, 20) { /* runs every second */ }

If you'd rather work with real time instead of ticks, TaskBuilder lets you use durations:

TaskBuilder(plugin)
    .async()
    .delay(TimeUtil.seconds(2))
    .repeat(TimeUtil.seconds(5))
    .run { /* your code */ }

TimeUtil can also turn a string like "1d2h30m" into a duration with TimeUtil.parse("1d2h30m"), which is handy for things like ban lengths or cooldown configs.