diff --git a/build.gradle b/build.gradle index 3183503..23dd92a 100644 --- a/build.gradle +++ b/build.gradle @@ -45,6 +45,8 @@ dependencies { compileOnly "org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT" implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.21" + implementation "dev.dejvokep:boosted-yaml-spigot:1.4" + shadow "org.bstats:bstats-bukkit:3.0.1" shadow "co.aikar:acf-paper:0.5.1-SNAPSHOT" } diff --git a/src/main/java/dev/mikchan/mcnp/motd/Creators.kt b/src/main/java/dev/mikchan/mcnp/motd/Creators.kt new file mode 100644 index 0000000..6970267 --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/motd/Creators.kt @@ -0,0 +1,8 @@ +package dev.mikchan.mcnp.motd + +import dev.mikchan.mcnp.motd.config.creator.IConfigCreator +import dev.mikchan.mcnp.motd.config.creator.boostedYaml.BoostedYamlConfigCreator + +object Creators { + var config: IConfigCreator = BoostedYamlConfigCreator() +} diff --git a/src/main/java/dev/mikchan/mcnp/motd/MotdPlugin.kt b/src/main/java/dev/mikchan/mcnp/motd/MotdPlugin.kt index 14c153c..853f808 100644 --- a/src/main/java/dev/mikchan/mcnp/motd/MotdPlugin.kt +++ b/src/main/java/dev/mikchan/mcnp/motd/MotdPlugin.kt @@ -1,5 +1,6 @@ package dev.mikchan.mcnp.motd +import dev.mikchan.mcnp.motd.config.config.IConfig import org.bstats.bukkit.Metrics import org.bukkit.plugin.java.JavaPlugin @@ -9,6 +10,8 @@ class MotdPlugin : JavaPlugin() { private const val BSTATS_ID = 20382 } + private val config: IConfig by lazy { Creators.config.build(this) } + override fun onEnable() { Metrics(this, BSTATS_ID) } diff --git a/src/main/java/dev/mikchan/mcnp/motd/config/config/IConfig.kt b/src/main/java/dev/mikchan/mcnp/motd/config/config/IConfig.kt new file mode 100644 index 0000000..81988de --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/motd/config/config/IConfig.kt @@ -0,0 +1,5 @@ +package dev.mikchan.mcnp.motd.config.config + +interface IConfig { + fun reload(): Boolean +} diff --git a/src/main/java/dev/mikchan/mcnp/motd/config/config/boostedYaml/BoostedYamlConfig.kt b/src/main/java/dev/mikchan/mcnp/motd/config/config/boostedYaml/BoostedYamlConfig.kt new file mode 100644 index 0000000..fc5d687 --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/motd/config/config/boostedYaml/BoostedYamlConfig.kt @@ -0,0 +1,27 @@ +package dev.mikchan.mcnp.motd.config.config.boostedYaml + +import dev.dejvokep.boostedyaml.YamlDocument +import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning +import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings +import dev.dejvokep.boostedyaml.settings.general.GeneralSettings +import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings +import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings +import dev.dejvokep.boostedyaml.spigot.SpigotSerializer +import dev.mikchan.mcnp.motd.config.config.IConfig +import java.io.File +import java.io.InputStream + +internal class BoostedYamlConfig(document: File, resource: InputStream) : IConfig { + private val config: YamlDocument = YamlDocument.create( + document, + resource, + GeneralSettings.builder().setSerializer(SpigotSerializer.getInstance()).build(), + LoaderSettings.builder().setAutoUpdate(true).build(), + DumperSettings.DEFAULT, + UpdaterSettings.builder().setVersioning(BasicVersioning("configVersion")).build(), + ) + + override fun reload(): Boolean { + return config.reload() + } +} diff --git a/src/main/java/dev/mikchan/mcnp/motd/config/creator/IConfigCreator.kt b/src/main/java/dev/mikchan/mcnp/motd/config/creator/IConfigCreator.kt new file mode 100644 index 0000000..7b6630c --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/motd/config/creator/IConfigCreator.kt @@ -0,0 +1,8 @@ +package dev.mikchan.mcnp.motd.config.creator + +import dev.mikchan.mcnp.motd.MotdPlugin +import dev.mikchan.mcnp.motd.config.config.IConfig + +interface IConfigCreator { + fun build(plugin: MotdPlugin): IConfig +} diff --git a/src/main/java/dev/mikchan/mcnp/motd/config/creator/boostedYaml/BoostedYamlConfigCreator.kt b/src/main/java/dev/mikchan/mcnp/motd/config/creator/boostedYaml/BoostedYamlConfigCreator.kt new file mode 100644 index 0000000..a20f85d --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/motd/config/creator/boostedYaml/BoostedYamlConfigCreator.kt @@ -0,0 +1,15 @@ +package dev.mikchan.mcnp.motd.config.creator.boostedYaml + +import dev.mikchan.mcnp.motd.MotdPlugin +import dev.mikchan.mcnp.motd.config.config.IConfig +import dev.mikchan.mcnp.motd.config.config.boostedYaml.BoostedYamlConfig +import dev.mikchan.mcnp.motd.config.creator.IConfigCreator +import java.io.File + +internal class BoostedYamlConfigCreator : IConfigCreator { + override fun build(plugin: MotdPlugin): IConfig { + val resource = plugin.getResource("config.yml")!! + val document = File(plugin.dataFolder, "config.yml") + return BoostedYamlConfig(document, resource) + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index beb923f..df42c14 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -13,3 +13,4 @@ load: STARTUP libraries: - org.jetbrains.kotlin:kotlin-stdlib:1.9.21 + - dev.dejvokep:boosted-yaml-spigot:1.4