All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.ZeronDev.coroutine.RepeatingScheduler.kt Maven / Gradle / Ivy

There is a newer version: 2.7.2
Show newest version
package io.github.ZeronDev.coroutine

import io.github.ZeronDev.LibraryPlugin.plugin
import org.bukkit.Bukkit
import org.bukkit.scheduler.BukkitTask

class RepeatingScheduler {
    var scheduler: BukkitTask? = null
    companion object {
        fun scheduleWith(period: Int, func: ()->Unit) : RepeatingScheduler {
            val sch = RepeatingScheduler()
            sch.apply {
                scheduler = Bukkit.getScheduler().runTaskTimerAsynchronously(plugin!!,
                Runnable { func() }, 0L, period.toLong())
            }
            return sch
        }
    }
    fun stop() {
        scheduler?.cancel()
        scheduler = null
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy