Skip to content

Commit

Permalink
Add mix-motd config
Browse files Browse the repository at this point in the history
  • Loading branch information
wtlgo committed Nov 26, 2023
1 parent c524d53 commit d8abc26
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interface IConfig {

var enabled: Boolean
var randomImages: Boolean
var mixMotd: Boolean
var motd: List<IMOTDConfig>
var personalizedMotd: List<IMOTDConfig>
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ internal class BoostedYamlConfig(document: File, resource: InputStream) : IConfi
config.set("random-images", value)
config.save()
}

override var mixMotd: Boolean
get() = config.getBoolean("mix-motd", false)
set(value) {
config.set("mix-motd", value)
config.save()
}

override var motd: List<IMOTDConfig>
get() = config.getMapList("motd", listOf()).filterNotNull().map { BoostedYamlProxyMOTDConfig(it) }
set(value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import dev.mikchan.mcnp.motd.MOTDPlugin

internal class MOTDManager(private val plugin: MOTDPlugin) : IMOTDManager {
override fun getRandom(personalized: Boolean): IMOTD? {
val motd = if (personalized) plugin.config.motd + plugin.config.personalizedMotd else plugin.config.motd
val motd = if (!personalized) {
plugin.config.motd
} else if (plugin.config.mixMotd) {
plugin.config.motd + plugin.config.personalizedMotd
} else {
plugin.config.personalizedMotd
}

return motd.ifEmpty { null }?.random()?.let { MOTDProxy(it, plugin.imageManager) }
}
}
4 changes: 3 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ config-version: 1

enabled: false
random-images: false
mix-motd: false

motd:
- first-line: Minecraft
second-line: Server
image: image.png
image: image

personalized-motd:
- first-line: Minecraft Server
Expand Down

0 comments on commit d8abc26

Please sign in to comment.