From 3b485c4d4134515612b55874980f7034f3bc1f5b Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Wed, 10 Nov 2021 19:23:56 +0100 Subject: [PATCH] Use auto-saver system in plugin --- src/main/kotlin/PortalsPlugin.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/PortalsPlugin.kt b/src/main/kotlin/PortalsPlugin.kt index a47156c..4bbf663 100644 --- a/src/main/kotlin/PortalsPlugin.kt +++ b/src/main/kotlin/PortalsPlugin.kt @@ -42,6 +42,8 @@ class PortalsPlugin: JavaPlugin() { val pluginCommand = getCommand("portals")!! pluginCommand.tabCompleter = command pluginCommand.setExecutor(command) + + startAutoSaver() } override fun reloadConfig() { @@ -52,14 +54,19 @@ class PortalsPlugin: JavaPlugin() { portalManager.reload() } - private fun startAutoSaver() { + private fun cancelAutoSaver() { val task = autoSaveTask if (task != null) { Bukkit.getScheduler().cancelTask(task.taskId) + autoSaveTask = null } + } + + private fun startAutoSaver() { + if (autoSaveTask != null) + cancelAutoSaver() val interval = config.getLong(PATH_AUTOSAVE, AUTOSAVE_DEFAULT) - autoSaveTask = Bukkit.getScheduler().runTaskTimer( this, Runnable { @@ -76,6 +83,8 @@ class PortalsPlugin: JavaPlugin() { override fun onDisable() { super.onDisable() + cancelAutoSaver() + portalManager.onDisable() data.save()