summaryrefslogtreecommitdiff
path: root/src/main/kotlin/io/dico/parcels2/util/PluginAware.kt
blob: b55f991854f14fd2ef7e3ea772760879a5177b5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@file:Suppress("RedundantLambdaArrow")

package io.dico.parcels2.util

import org.bukkit.plugin.Plugin
import org.bukkit.scheduler.BukkitTask

interface PluginAware {
    val plugin: Plugin
}

inline fun PluginAware.schedule(delay: Int = 0, crossinline task: () -> Unit): BukkitTask {
    return plugin.server.scheduler.runTaskLater(plugin, { -> task() }, delay.toLong())
}

inline fun PluginAware.scheduleRepeating(interval: Int, delay: Int = 0, crossinline task: () -> Unit): BukkitTask {
    return plugin.server.scheduler.runTaskTimer(plugin, { -> task() }, delay.toLong(), interval.toLong())
}