From 0674b36fbfe12645ba93d0c4f2fddc1aa3323ba3 Mon Sep 17 00:00:00 2001 From: TomTom <93038247+AverageGithub@users.noreply.github.com> Date: Thu, 30 May 2024 15:56:18 +0200 Subject: [PATCH] Config autoupdate --- .../api/minions/miniontype/MinionType.kt | 32 +++++++++++++------ .../minions/miniontype/MinerMinionType.kt | 2 +- common/src/main/resources/minions/miner.yml | 4 ++- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/minions/miniontype/MinionType.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/minions/miniontype/MinionType.kt index d04ee21..4254ba9 100644 --- a/api/src/main/kotlin/com/artillexstudios/axminions/api/minions/miniontype/MinionType.kt +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/minions/miniontype/MinionType.kt @@ -2,6 +2,7 @@ package com.artillexstudios.axminions.api.minions.miniontype import com.artillexstudios.axapi.config.Config import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.block.implementation.Section +import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.dvs.versioning.BasicVersioning import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.settings.dumper.DumperSettings import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.settings.general.GeneralSettings import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.settings.loader.LoaderSettings @@ -16,18 +17,31 @@ import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder import org.bukkit.inventory.ItemStack import org.bukkit.persistence.PersistentDataType -abstract class MinionType(private val name: String, private val defaults: InputStream) { +abstract class MinionType(private val name: String, private val defaults: InputStream, private val autoUpdateConfig: Boolean) { private lateinit var config: Config + constructor(name: String, defaults: InputStream) : this(name, defaults, false) + fun load() { - config = Config( - File(AxMinionsAPI.INSTANCE.getAxMinionsDataFolder(), "/minions/$name.yml"), - defaults, - GeneralSettings.builder().setUseDefaults(false).build(), - LoaderSettings.DEFAULT, - DumperSettings.DEFAULT, - UpdaterSettings.DEFAULT - ) + if (!autoUpdateConfig) { + config = Config( + File(AxMinionsAPI.INSTANCE.getAxMinionsDataFolder(), "/minions/$name.yml"), + defaults, + GeneralSettings.builder().setUseDefaults(false).build(), + LoaderSettings.DEFAULT, + DumperSettings.DEFAULT, + UpdaterSettings.DEFAULT + ) + } else { + config = Config( + File(AxMinionsAPI.INSTANCE.getAxMinionsDataFolder(), "/minions/$name.yml"), + defaults, + GeneralSettings.builder().setUseDefaults(false).build(), + LoaderSettings.builder().setAutoUpdate(true).build(), + DumperSettings.DEFAULT, + UpdaterSettings.builder().setVersioning(BasicVersioning("config-version")).build() + ) + } AxMinionsAPI.INSTANCE.getDataHandler().insertType(this) } diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/MinerMinionType.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/MinerMinionType.kt index b3b324b..16902e6 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/MinerMinionType.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/MinerMinionType.kt @@ -27,7 +27,7 @@ import org.bukkit.enchantments.Enchantment import org.bukkit.inventory.FurnaceRecipe import org.bukkit.inventory.ItemStack -class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource("minions/miner.yml")!!) { +class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource("minions/miner.yml")!!, true) { companion object { private var asyncExecutor: ExecutorService? = null private val smeltingRecipes = ArrayList() diff --git a/common/src/main/resources/minions/miner.yml b/common/src/main/resources/minions/miner.yml index 56694c7..037a20f 100644 --- a/common/src/main/resources/minions/miner.yml +++ b/common/src/main/resources/minions/miner.yml @@ -156,4 +156,6 @@ upgrades: boots: type: LEATHER_BOOTS color: "150, 150, 150" - glow: true \ No newline at end of file + glow: true + +config-version: 1 \ No newline at end of file