Skip to content

Commit

Permalink
feat(shulker-server-agent): hybrid support between paper and folia
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylvln committed Nov 2, 2023
1 parent 78650e1 commit 0b151eb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ subprojects {

dependencies {
"commonCompileOnly"("net.kyori:adventure-api:4.14.0")
"paperCompileOnly"("io.papermc.paper:paper-api:1.19.3-R0.1-SNAPSHOT")
"paperCompileOnly"("dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
package io.shulkermc.serveragent.paper

import io.papermc.paper.threadedregions.scheduler.ScheduledTask
import io.shulkermc.serveragent.ServerInterface
import org.bukkit.scheduler.BukkitTask
import java.util.concurrent.TimeUnit

class ServerInterfacePaper(private val plugin: ShulkerServerAgentPaper) : ServerInterface {
companion object {
private const val TICKS_PER_SECONDS = 20L
}

override fun scheduleDelayedTask(
delay: Long,
timeUnit: TimeUnit,
runnable: Runnable
): ServerInterface.ScheduledTask {
val delayTicks = timeUnit.toSeconds(delay) * TICKS_PER_SECONDS
return BukkitScheduledTask(
this.plugin.server.scheduler.runTaskLaterAsynchronously(this.plugin, runnable, delayTicks)
return PaperScheduledTask(
this.plugin.server.asyncScheduler.runDelayed(this.plugin, { runnable.run() }, delay, timeUnit)
)
}

Expand All @@ -26,16 +21,14 @@ class ServerInterfacePaper(private val plugin: ShulkerServerAgentPaper) : Server
timeUnit: TimeUnit,
runnable: Runnable
): ServerInterface.ScheduledTask {
val delayTicks = timeUnit.toSeconds(delay) * TICKS_PER_SECONDS
val intervalTicks = timeUnit.toSeconds(interval) * TICKS_PER_SECONDS
return BukkitScheduledTask(
this.plugin.server.scheduler.runTaskTimerAsynchronously(this.plugin, runnable, delayTicks, intervalTicks)
return PaperScheduledTask(
this.plugin.server.asyncScheduler.runAtFixedRate(this.plugin, { runnable.run() }, delay, interval, timeUnit)
)
}

private class BukkitScheduledTask(private val bukkitTask: BukkitTask) : ServerInterface.ScheduledTask {
private class PaperScheduledTask(private val scheduledTask: ScheduledTask) : ServerInterface.ScheduledTask {
override fun cancel() {
if (!this.bukkitTask.isCancelled) this.bukkitTask.cancel()
if (!this.scheduledTask.isCancelled) this.scheduledTask.cancel()
}
}
}
5 changes: 3 additions & 2 deletions packages/shulker-server-agent/src/paper/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: ShulkerServerAgent
main: io.shulkermc.serveragent.paper.ShulkerServerAgentPaper
version: ${version}
author: Jérémy Levilain <jeremy@jeremylvln.fr>
api-version: 1.19
main: io.shulkermc.serveragent.paper.ShulkerServerAgentPaper
author: Jérémy Levilain <jeremy@jeremylvln.fr>
folia-supported: true

0 comments on commit 0b151eb

Please sign in to comment.