Update KSpigotRunnables.kt

This commit is contained in:
bluefireoly
2020-10-23 00:08:41 +02:00
parent ba95c1d286
commit 53994d3c4b

View File

@@ -96,18 +96,31 @@ fun task(
if (endCallback != null) KRunnableHolder.add(bukkitRunnable, endCallback, safe)
if (sync)
bukkitRunnable.runTaskTimer(KSpigotMainInstance, delay, period ?: 20)
if (period != null)
if (sync) bukkitRunnable.runTaskTimer(KSpigotMainInstance, delay, period)
else bukkitRunnable.runTaskTimerAsynchronously(KSpigotMainInstance, delay, period)
else
bukkitRunnable.runTaskTimerAsynchronously(KSpigotMainInstance, delay, period ?: 20)
if (sync) bukkitRunnable.runTaskLater(KSpigotMainInstance, delay)
else bukkitRunnable.runTaskLaterAsynchronously(KSpigotMainInstance, delay)
}
/**
* Executes the given [runnable] with the given [delay].
* Either sync or async (specified by the [sync] parameter).
*/
fun bukkitRunLater(delay: Long, sync: Boolean = true, runnable: () -> Unit) {
if (sync)
Bukkit.getScheduler().runTaskLater(KSpigotMainInstance, runnable, delay)
else
Bukkit.getScheduler().runTaskLaterAsynchronously(KSpigotMainInstance, runnable, delay)
}
/**
* Executes the given [runnable] either
* sync or async (specified by the [sync] parameter).
*/
fun bukkitRun(sync: Boolean, runnable: () -> Unit) {
fun bukkitRun(sync: Boolean = true, runnable: () -> Unit) {
if (sync) {
sync(runnable)
} else {