Implement auto-saving of portal data
This commit is contained in:
parent
d0db1a9f5b
commit
bfaae59d51
@ -6,7 +6,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "dev.w1zzrd"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
@ -1,11 +1,18 @@
|
||||
import kr.entree.spigradle.annotations.SpigotPlugin
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.plugin.java.JavaPlugin
|
||||
import org.bukkit.scheduler.BukkitTask
|
||||
import java.io.File
|
||||
|
||||
private const val PATH_AUTOSAVE = "autoSaveMinutesInterval"
|
||||
private const val AUTOSAVE_DEFAULT = 240L
|
||||
|
||||
|
||||
@SpigotPlugin
|
||||
class PortalsPlugin: JavaPlugin() {
|
||||
private val data = YamlFile.loadFile(File(dataFolder, "data.yml"))
|
||||
private val portalManager = PortalManager(data) { config }
|
||||
private var autoSaveTask: BukkitTask? = null
|
||||
|
||||
override fun onEnable() {
|
||||
super.onEnable()
|
||||
@ -45,6 +52,27 @@ class PortalsPlugin: JavaPlugin() {
|
||||
portalManager.reload()
|
||||
}
|
||||
|
||||
private fun startAutoSaver() {
|
||||
val task = autoSaveTask
|
||||
if (task != null) {
|
||||
Bukkit.getScheduler().cancelTask(task.taskId)
|
||||
}
|
||||
|
||||
val interval = config.getLong(PATH_AUTOSAVE, AUTOSAVE_DEFAULT)
|
||||
|
||||
autoSaveTask = Bukkit.getScheduler().runTaskTimer(
|
||||
this,
|
||||
Runnable {
|
||||
Bukkit.getLogger().info("Triggered auto-save")
|
||||
portalManager.save()
|
||||
data.save()
|
||||
Bukkit.getLogger().info("Auto-save complete")
|
||||
},
|
||||
interval,
|
||||
interval
|
||||
)
|
||||
}
|
||||
|
||||
override fun onDisable() {
|
||||
super.onDisable()
|
||||
|
||||
|
@ -1,2 +1,3 @@
|
||||
chunkLoadDestination: true
|
||||
autoSaveMinutesInterval: 240
|
||||
playerTeleportCooldownTicks: 100
|
Loading…
x
Reference in New Issue
Block a user