Add task documentation

This commit is contained in:
Jakob K
2021-04-23 22:24:00 +00:00
parent 6823a608c6
commit 20b21190b6
2 changed files with 37 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
## The general task function
The task function is very powerful. It connects almost all kinds of Spigot tasks and even adds additional features on top.
You define its behaviour by providing the following parameters (all are optional and have default values):
| Parameter | Description |
| ---------------- | ------------- |
| sync | if the runnable should run sync (true) or async (false) |
| delay | the delay (in ticks) until the first execution of the task |
| period | at which interval (in ticks) the task should be repeated |
| howOften | how many times the task should be executed - null for infinite execution |
| endCallback | code that should always be executed when the runnable ends |
| safe | if the endCallback of the runnable should always be executed, even if the server shuts down or the runnable ends prematurely |
| runnable | the runnable which should be executed each repetition |
The body of task function is the `runnable` parameter. This runnable provides an instance of `KSpigotRunnable`, which inherits from `BukkitRunnable`, but adds counters on top. These counters are:
- `counterUp`
- `counterDownToOne`
- `counterDownToZero`
An example would be:
```kotlin
task(
sync = false,
delay = 25,
period = 20,
howOften = 5
) {
println(it.counterUp) // starting from zero
println(it.counterDownToOne) // starting from howOften
println(it.counterDownToZero) // starting from howOften - 1
}
```

View File

@@ -33,3 +33,4 @@ nav:
- Entrypoint to your plugin: setup/entrypoint.md
- Extensions:
- Event listener: extensions/listener.md
- Tasks: extensions/tasks.md