Skip to content

Commit

Permalink
Add config
Browse files Browse the repository at this point in the history
  • Loading branch information
wtlgo committed Nov 26, 2023
1 parent 46f70a5 commit dcaa75e
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/dev/mikchan/mcnp/motd/Creators.kt
Original file line number Diff line number Diff line change
@@ -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()
}
3 changes: 3 additions & 0 deletions src/main/java/dev/mikchan/mcnp/motd/MotdPlugin.kt
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dev/mikchan/mcnp/motd/config/config/IConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dev.mikchan.mcnp.motd.config.config

interface IConfig {
fun reload(): Boolean
}
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ load: STARTUP

libraries:
- org.jetbrains.kotlin:kotlin-stdlib:1.9.21
- dev.dejvokep:boosted-yaml-spigot:1.4

0 comments on commit dcaa75e

Please sign in to comment.