Skip to content

Commit 8fa86f8

Browse files
refactor: update motd system and add layout system
1 parent eaf12ea commit 8fa86f8

File tree

13 files changed

+93
-18
lines changed

13 files changed

+93
-18
lines changed

.idea/gradle.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proxy-bungeecord/src/main/kotlin/app/simplecloud/plugin/proxy/bungeecord/ProxyBungeeCordPlugin.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import app.simplecloud.plugin.proxy.bungeecord.handler.TabListHandler
55
import app.simplecloud.plugin.proxy.bungeecord.listener.ConfigureTagResolversListener
66
import app.simplecloud.plugin.proxy.bungeecord.listener.ProxyPingListener
77
import app.simplecloud.plugin.proxy.bungeecord.listener.TabListListener
8+
import app.simplecloud.plugin.proxy.shared.config.GeneralConfig
89
import app.simplecloud.plugin.proxy.shared.config.YamlConfig
9-
import app.simplecloud.plugin.proxy.shared.config.motd.MotdConfiguration
10+
import app.simplecloud.plugin.proxy.shared.config.motd.MotdLayoutConfiguration
1011
import app.simplecloud.plugin.proxy.shared.config.placeholder.PlaceHolderConfiguration
1112
import app.simplecloud.plugin.proxy.shared.config.tablis.TabListConfiguration
13+
import app.simplecloud.plugin.proxy.shared.handler.MotdLayoutHandler
1214
import net.kyori.adventure.platform.bungeecord.BungeeAudiences
1315
import net.kyori.adventure.text.Component
1416
import net.kyori.adventure.text.minimessage.MiniMessage
@@ -18,11 +20,13 @@ import net.md_5.bungee.api.plugin.Plugin
1820

1921
class ProxyBungeeCordPlugin: Plugin() {
2022

21-
lateinit var motdConfiguration: MotdConfiguration
23+
lateinit var generalConfiguration: GeneralConfig
2224
lateinit var tabListConfiguration: TabListConfiguration
2325
lateinit var placeHolderConfiguration: PlaceHolderConfiguration
2426

27+
val config = YamlConfig(this.dataFolder.path)
2528
val tabListHandler = TabListHandler(this)
29+
val motdLayoutHandler = MotdLayoutHandler(config, generalConfiguration)
2630

2731
private var adventure: BungeeAudiences? = null
2832

@@ -31,15 +35,17 @@ class ProxyBungeeCordPlugin: Plugin() {
3135
override fun onEnable() {
3236
val config = YamlConfig(this.dataFolder.path)
3337

34-
this.motdConfiguration = config.load<MotdConfiguration>("motd")!!
35-
config.save("motd", this.motdConfiguration)
38+
this.generalConfiguration = config.load<GeneralConfig>("general")!!
39+
config.save("general", this.generalConfiguration)
3640

3741
this.tabListConfiguration = config.load<TabListConfiguration>("tablist")!!
3842
config.save("tablist", this.tabListConfiguration)
3943

4044
this.placeHolderConfiguration = config.load<PlaceHolderConfiguration>("placeholder")!!
4145
config.save("placeholder", this.placeHolderConfiguration)
4246

47+
this.motdLayoutHandler.loadMotdLayouts()
48+
4349
this.adventure = BungeeAudiences.create(this);
4450

4551
if (this.tabListConfiguration.tabListUpdateTime > 0)

proxy-bungeecord/src/main/kotlin/app/simplecloud/plugin/proxy/bungeecord/listener/ConfigureTagResolversListener.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ConfigureTagResolversListener(
2929
pingColors,
3030
onlinePlayers,
3131
realMaxPlayers,
32-
this.plugin.motdConfiguration
32+
this.plugin.motdLayoutHandler.getCurrentMotdLayout()
3333
)
3434
)
3535
}

proxy-bungeecord/src/main/kotlin/app/simplecloud/plugin/proxy/bungeecord/listener/ProxyPingListener.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ProxyPingListener(
3030

3131
val response = event.response
3232

33-
val motdConfiguration = this.plugin.motdConfiguration
33+
val motdConfiguration = this.plugin.motdLayoutHandler.getCurrentMotdLayout()
3434

3535
val firstLine = motdConfiguration.firstLines.random()
3636
val secondLine = motdConfiguration.secondLines.random()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package app.simplecloud.plugin.proxy.shared.config
2+
3+
import org.spongepowered.configurate.objectmapping.ConfigSerializable
4+
5+
@ConfigSerializable
6+
data class GeneralConfig(
7+
var currentLayout: String = "default-motd"
8+
)

proxy-shared/src/main/kotlin/app/simplecloud/plugin/proxy/shared/config/YamlConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import org.spongepowered.configurate.yaml.NodeStyle
77
import org.spongepowered.configurate.yaml.YamlConfigurationLoader
88
import java.io.File
99

10-
open class YamlConfig(private val dirPath: String) {
10+
open class YamlConfig(val dirPath: String) {
1111

1212
inline fun <reified T> load(): T? {
1313
return load(null)

proxy-shared/src/main/kotlin/app/simplecloud/plugin/proxy/shared/config/motd/MotdConfiguration.kt renamed to proxy-shared/src/main/kotlin/app/simplecloud/plugin/proxy/shared/config/motd/MotdLayoutConfiguration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package app.simplecloud.plugin.proxy.shared.config.motd
33
import org.spongepowered.configurate.objectmapping.ConfigSerializable
44

55
@ConfigSerializable
6-
data class MotdConfiguration(
6+
data class MotdLayoutConfiguration(
77
val firstLines: List<String> = listOf("<gradient:#00fcff:#0da1a3><bold>SimpleCloud</bold></gradient> <dark_gray>»<gray> Simplify your network <dark_gray>|<bold><#4595ff> 1.12<#545454> - <#4595ff>1.20</bold>"),
88
val secondLines: List<String> = listOf("<dark_gray>× <#178fff>Status<dark_gray>: <bold><#22cc22>Online</bold> <dark_gray>- <#ffffff>%PROXY%"),
99
val playerInfo: List<String> = listOf(),
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package app.simplecloud.plugin.proxy.shared.handler
2+
3+
import app.simplecloud.plugin.proxy.shared.config.GeneralConfig
4+
import app.simplecloud.plugin.proxy.shared.config.YamlConfig
5+
import app.simplecloud.plugin.proxy.shared.config.motd.MotdLayoutConfiguration
6+
import java.io.File
7+
8+
class MotdLayoutHandler(
9+
val yamlConfig: YamlConfig,
10+
val generalConfig: GeneralConfig
11+
) {
12+
13+
private val loadedMotdLayouts: MutableMap<String, MotdLayoutConfiguration> = mutableMapOf()
14+
15+
fun loadMotdLayouts() {
16+
loadedMotdLayouts.clear()
17+
val directory = File(yamlConfig.dirPath + "/layout")
18+
19+
if (!directory.exists()) {
20+
directory.mkdirs()
21+
}
22+
23+
directory.listFiles()?.forEach {
24+
val name = it.nameWithoutExtension
25+
val motdLayout = yamlConfig.load<MotdLayoutConfiguration>("layout/$name")
26+
if (motdLayout != null) {
27+
loadedMotdLayouts[name] = motdLayout
28+
println("Loaded motd layout: $name")
29+
}
30+
}
31+
32+
if (loadedMotdLayouts.isEmpty()) {
33+
println("No motd layouts found, creating default motd layout")
34+
val defaultMotdLayout = MotdLayoutConfiguration()
35+
yamlConfig.save("layout/default-motd", defaultMotdLayout)
36+
loadedMotdLayouts["default-motd"] = defaultMotdLayout
37+
}
38+
}
39+
40+
fun getMotdLayout(name: String): MotdLayoutConfiguration {
41+
return loadedMotdLayouts[name] ?: MotdLayoutConfiguration()
42+
}
43+
44+
fun getCurrentMotdLayout(): MotdLayoutConfiguration {
45+
return getMotdLayout(generalConfig.currentLayout)
46+
}
47+
48+
fun getLoadedMotdLayouts(): List<String> {
49+
return loadedMotdLayouts.keys.toList()
50+
}
51+
52+
fun setMotdLayout(name: String) {
53+
generalConfig.currentLayout = name
54+
yamlConfig.save("general", generalConfig)
55+
}
56+
}

proxy-shared/src/main/kotlin/app/simplecloud/plugin/proxy/shared/resolver/TagResolverHelper.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package app.simplecloud.plugin.proxy.shared.resolver
22

33
import app.simplecloud.plugin.proxy.shared.config.motd.MaxPlayerDisplayType
4-
import app.simplecloud.plugin.proxy.shared.config.motd.MotdConfiguration
4+
import app.simplecloud.plugin.proxy.shared.config.motd.MotdLayoutConfiguration
55
import app.simplecloud.plugin.proxy.shared.config.placeholder.PingColor
66
import net.kyori.adventure.text.minimessage.Context
77
import net.kyori.adventure.text.minimessage.tag.Tag
@@ -21,7 +21,7 @@ object TagResolverHelper {
2121
pingColors: List<PingColor>,
2222
onlinePlayers: Int,
2323
realMaxPlayers: Int,
24-
motdConfiguration: MotdConfiguration
24+
motdConfiguration: MotdLayoutConfiguration
2525
): List<TagResolver> {
2626
return listOf(
2727
Placeholder.unparsed(TagResolverNames.SERVER_NAME, serverName),
@@ -46,7 +46,7 @@ object TagResolverHelper {
4646
fun getMaxPlayersTagResolver(
4747
onlinePlayers: Int,
4848
realMaxPlayers: Int,
49-
motdConfiguration: MotdConfiguration
49+
motdConfiguration: MotdLayoutConfiguration
5050
): TagResolver {
5151
val maxPlayers = when (motdConfiguration.maxPlayerDisplayType) {
5252
MaxPlayerDisplayType.REAL -> realMaxPlayers

0 commit comments

Comments
 (0)