Skip to content

Commit

Permalink
Add few configs more
Browse files Browse the repository at this point in the history
  • Loading branch information
wtlgo committed Nov 26, 2023
1 parent 4b33eef commit 07ba6e1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/dev/mikchan/mcnp/motd/config/config/IConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ interface IConfig {
fun reload(): Boolean

var enabled: Boolean
var randomImages: Boolean
var motd: List<IMOTDConfig>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.mikchan.mcnp.motd.config.config

interface IMOTDConfig {
val firstLine: String?
val secondLine: String?
val image: String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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 dev.mikchan.mcnp.motd.config.config.IMOTDConfig
import java.io.File
import java.io.InputStream

Expand All @@ -31,4 +32,22 @@ internal class BoostedYamlConfig(document: File, resource: InputStream) : IConfi
config.set("enabled", value)
config.save()
}

override var randomImages: Boolean
get() = config.getBoolean("random-images", false)
set(value) {
config.set("random-images", value)
config.save()
}
override var motd: List<IMOTDConfig>
get() = config.getMapList("motd", listOf()).filterNotNull().map { BoostedYamlProxyMOTDConfig(it) }
set(value) {
config.set("motd", value.map {
mapOf(
"first-line" to it.firstLine,
"second-line" to it.secondLine,
"image" to it.image,
).filter { m -> m.value != null }
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.mikchan.mcnp.motd.config.config.boostedYaml

import dev.mikchan.mcnp.motd.config.config.IMOTDConfig

internal class BoostedYamlProxyMOTDConfig(private val motd: Map<*, *>) : IMOTDConfig {
override val firstLine: String?
get() = motd["first-line"] as? String

override val secondLine: String?
get() = motd["second-line"] as? String

override val image: String?
get() = motd["image"] as? String
}
5 changes: 5 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
config-version: 1

enabled: false
random-images: false
motd:
- first-line: Minecraft
second-line: Server
image: image.png

0 comments on commit 07ba6e1

Please sign in to comment.