Updated folia scheduler

This commit is contained in:
Auxilor
2023-05-09 13:48:57 +01:00
parent b9c5eb2b4e
commit 55fc6d762f
3 changed files with 30 additions and 12 deletions

View File

@@ -1,7 +0,0 @@
group 'com.willfp'
version rootProject.version
dependencies {
//compileOnly 'dev.folia:folia-api:1.19.3-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT'
}

View File

@@ -0,0 +1,6 @@
group = "com.willfp"
version = rootProject.version
dependencies {
compileOnly("dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT")
}

View File

@@ -2,29 +2,48 @@ package com.willfp.eco.internal.scheduling
import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.scheduling.Scheduler import com.willfp.eco.core.scheduling.Scheduler
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.scheduler.BukkitTask
import java.util.concurrent.TimeUnit
class EcoSchedulerFolia(private val plugin: EcoPlugin) : Scheduler { class EcoSchedulerFolia(private val plugin: EcoPlugin) : Scheduler {
override fun runLater(runnable: Runnable, ticksLater: Long): BukkitTask {
Bukkit.getGlobalRegionScheduler().runDelayed(plugin, { runnable.run() }, ticksLater)
}
override fun runLater(location: Location, ticksLater: Int, task: Runnable): BukkitTask { override fun runLater(location: Location, ticksLater: Int, task: Runnable): BukkitTask {
return Bukkit.getScheduler().runTaskLater(plugin, task, ticksLater.toLong()) Bukkit.getRegionScheduler().runDelayed(plugin, location, { task.run() }, ticksLater.toLong())
}
override fun runTimer(delay: Long, repeat: Long, runnable: Runnable): BukkitTask {
Bukkit.getGlobalRegionScheduler().runAtFixedRate(plugin, { runnable.run() }, delay, repeat)
} }
override fun runTimer(location: Location, delay: Int, repeat: Int, task: Runnable): BukkitTask { override fun runTimer(location: Location, delay: Int, repeat: Int, task: Runnable): BukkitTask {
return Bukkit.getScheduler().runTaskTimer(plugin, task, delay.toLong(), repeat.toLong()) Bukkit.getRegionScheduler().runAtFixedRate(plugin, location, { task.run() }, delay.toLong(), repeat.toLong())
}
override fun run(runnable: Runnable): BukkitTask {
Bukkit.getGlobalRegionScheduler().run(plugin) { runnable.run() }
} }
override fun run(location: Location, task: Runnable): BukkitTask { override fun run(location: Location, task: Runnable): BukkitTask {
return Bukkit.getScheduler().runTask(plugin, task) Bukkit.getRegionScheduler().run(plugin, location) { task.run() }
} }
override fun runAsync(task: Runnable): BukkitTask { override fun runAsync(task: Runnable): BukkitTask {
return Bukkit.getScheduler().runTaskAsynchronously(plugin, task) Bukkit.getAsyncScheduler().runNow(plugin) { task.run() }
} }
override fun runTimerAsync(delay: Int, repeat: Int, task: Runnable): BukkitTask { override fun runTimerAsync(delay: Int, repeat: Int, task: Runnable): BukkitTask {
return Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, task, delay.toLong(), repeat.toLong()) Bukkit.getAsyncScheduler()
.runAtFixedRate(plugin, { task.run() }, delay * 50L, repeat * 50L, TimeUnit.MILLISECONDS)
} }
override fun cancelAll() { override fun cancelAll() {
Bukkit.getScheduler().cancelTasks(plugin) Bukkit.getScheduler().cancelTasks(plugin)
Bukkit.getAsyncScheduler().cancelTasks(plugin)
Bukkit.getGlobalRegionScheduler().cancelTasks(plugin)
} }
} }