Skip to content

Commit

Permalink
Migrate bukkit main dispatcher to updated scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
vjh0107 committed Jan 27, 2024
1 parent 56e5167 commit 6318bb0
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.bukkit.Bukkit
import org.bukkit.Server
import org.bukkit.plugin.IllegalPluginAccessException
import org.bukkit.plugin.Plugin
import org.bukkit.scheduler.BukkitRunnable
import org.bukkit.scheduler.BukkitScheduler
import kotlin.coroutines.CoroutineContext

Expand All @@ -27,11 +28,23 @@ open class BukkitMainDispatcher(
}

open fun runTask(plugin: Plugin, task: () -> Unit): BukkitScheduledTask {
return DefaultBukkitScheduledTask(scheduler, scheduler.runTask(plugin, task))
val bukkitRunnable = object : BukkitRunnable() {
override fun run() {
task.invoke()
}
}
bukkitRunnable.runTask(plugin)
return DefaultBukkitScheduledTask(scheduler, bukkitRunnable, plugin)
}

open fun runTaskWithFixedDelay(plugin: Plugin, delay: Long, task: () -> Unit): BukkitScheduledTask {
return DefaultBukkitScheduledTask(scheduler, scheduler.runTaskLater(plugin, task, delay))
val bukkitRunnable = object : BukkitRunnable() {
override fun run() {
task.invoke()
}
}
bukkitRunnable.runTaskLater(plugin, delay)
return DefaultBukkitScheduledTask(scheduler, bukkitRunnable, plugin)
}

final override fun dispatch(context: CoroutineContext, block: Runnable) {
Expand Down

0 comments on commit 6318bb0

Please sign in to comment.