Applied kotlin style conventions
This commit is contained in:
@@ -82,8 +82,7 @@ class ChainedRunnablePartFirst<R>(
|
||||
sync: Boolean
|
||||
) : ChainedRunnablePart<Unit, R>(sync) {
|
||||
|
||||
override fun execute()
|
||||
= start(Unit)
|
||||
override fun execute() = start(Unit)
|
||||
|
||||
override fun <E : Exception> executeCatchingImpl(
|
||||
exceptionClass: KClass<E>,
|
||||
@@ -101,8 +100,7 @@ class ChainedRunnablePartThen<T, R>(
|
||||
val previous: ChainedRunnablePart<*, T>
|
||||
) : ChainedRunnablePart<T, R>(sync) {
|
||||
|
||||
override fun execute()
|
||||
= previous.execute()
|
||||
override fun execute() = previous.execute()
|
||||
|
||||
override fun <E : Exception> executeCatchingImpl(
|
||||
exceptionClass: KClass<E>,
|
||||
@@ -115,13 +113,13 @@ class ChainedRunnablePartThen<T, R>(
|
||||
}
|
||||
|
||||
// FIRST
|
||||
fun <R> firstDo(sync: Boolean, runnable: () -> R)
|
||||
= ChainedRunnablePartFirst(runnable, sync)
|
||||
fun <R> firstDo(sync: Boolean, runnable: () -> R) = ChainedRunnablePartFirst(runnable, sync)
|
||||
fun <R> firstSync(runnable: () -> R) = firstDo(true, runnable)
|
||||
fun <R> firstAsync(runnable: () -> R) = firstDo(false, runnable)
|
||||
|
||||
// THEN
|
||||
fun <T, R, U> ChainedRunnablePart<T, R>.thenDo(sync: Boolean, runnable: (R) -> U)
|
||||
= ChainedRunnablePartThen(runnable, sync, this).apply { previous.next = this }
|
||||
fun <T, R, U> ChainedRunnablePart<T, R>.thenDo(sync: Boolean, runnable: (R) -> U) =
|
||||
ChainedRunnablePartThen(runnable, sync, this).apply { previous.next = this }
|
||||
|
||||
fun <T, R, U> ChainedRunnablePart<T, R>.thenSync(runnable: (R) -> U) = thenDo(true, runnable)
|
||||
fun <T, R, U> ChainedRunnablePart<T, R>.thenAsync(runnable: (R) -> U) = thenDo(false, runnable)
|
@@ -21,19 +21,18 @@ internal object KRunnableHolder : AutoCloseable {
|
||||
runnableEndCallbacks.clear()
|
||||
}
|
||||
|
||||
fun add(runnable: BukkitRunnable, callback: () -> Unit, safe: Boolean)
|
||||
= runnableEndCallbacks.put(runnable, Pair(callback, safe))
|
||||
fun remove(runnable: BukkitRunnable)
|
||||
= runnableEndCallbacks.remove(runnable)
|
||||
fun activate(runnable: BukkitRunnable)
|
||||
= runnableEndCallbacks.remove(runnable)?.first?.invoke()
|
||||
fun add(runnable: BukkitRunnable, callback: () -> Unit, safe: Boolean) =
|
||||
runnableEndCallbacks.put(runnable, Pair(callback, safe))
|
||||
|
||||
fun remove(runnable: BukkitRunnable) = runnableEndCallbacks.remove(runnable)
|
||||
fun activate(runnable: BukkitRunnable) = runnableEndCallbacks.remove(runnable)?.first?.invoke()
|
||||
|
||||
}
|
||||
|
||||
abstract class KSpigotRunnable(
|
||||
var counterUp: Long? = null,
|
||||
var counterDownToOne: Long? = null,
|
||||
var counterDownToZero: Long? = null
|
||||
var counterUp: Long? = null,
|
||||
var counterDownToOne: Long? = null,
|
||||
var counterDownToZero: Long? = null
|
||||
) : BukkitRunnable()
|
||||
|
||||
/**
|
||||
@@ -49,13 +48,13 @@ abstract class KSpigotRunnable(
|
||||
* @param runnable the runnable which should be executed each repetition
|
||||
*/
|
||||
fun task(
|
||||
sync: Boolean = true,
|
||||
delay: Long = 0,
|
||||
period: Long? = null,
|
||||
howOften: Long? = null,
|
||||
safe: Boolean = false,
|
||||
endCallback: (() -> Unit)? = null,
|
||||
runnable: ((KSpigotRunnable) -> Unit)? = null
|
||||
sync: Boolean = true,
|
||||
delay: Long = 0,
|
||||
period: Long? = null,
|
||||
howOften: Long? = null,
|
||||
safe: Boolean = false,
|
||||
endCallback: (() -> Unit)? = null,
|
||||
runnable: ((KSpigotRunnable) -> Unit)? = null
|
||||
) {
|
||||
|
||||
if (howOften != null && howOften == 0L) return
|
||||
@@ -119,11 +118,9 @@ fun bukkitRun(sync: Boolean, runnable: () -> Unit) {
|
||||
/**
|
||||
* Starts a synchronous task.
|
||||
*/
|
||||
fun sync(runnable: () -> Unit)
|
||||
= Bukkit.getScheduler().runTask(KSpigotMainInstance, runnable)
|
||||
fun sync(runnable: () -> Unit) = Bukkit.getScheduler().runTask(KSpigotMainInstance, runnable)
|
||||
|
||||
/**
|
||||
* Starts an asynchronous task.
|
||||
*/
|
||||
fun async(runnable: () -> Unit)
|
||||
= Bukkit.getScheduler().runTaskAsynchronously(KSpigotMainInstance, runnable)
|
||||
fun async(runnable: () -> Unit) = Bukkit.getScheduler().runTaskAsynchronously(KSpigotMainInstance, runnable)
|
Reference in New Issue
Block a user