Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit cfec4e4

Browse files
committed
refactor: centralize configuration handling and replace deprecated standaloneConfig references
- Introduced `AbstractSurfCloudConfig` and `AbstractSurfCloudConfigHolder` for consistent configuration management. - Replaced direct usage of `standaloneConfig` and similar references with injected config holders across applicable components. - Added new configuration data classes: `QueueConfig`, `ProxyConfig`, `KtorConfig`, `LoggingConfig`, and others. - Implemented commands for reloading and saving configuration via `ConfigCommand`. - Enhanced modularity and eliminated legacy configuration patterns to improve maintainability.
1 parent 26a6e9a commit cfec4e4

File tree

42 files changed

+524
-321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+524
-321
lines changed

surf-cloud-bukkit/src/main/kotlin/dev/slne/surf/cloud/bukkit/command/PaperCommandManager.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dev.slne.surf.cloud.bukkit.command
22

33
import dev.slne.surf.cloud.api.common.util.TimeLogger
44
import dev.slne.surf.cloud.bukkit.command.broadcast.broadcastCommand
5+
import dev.slne.surf.cloud.bukkit.command.cloud.cloudCommand
56
import dev.slne.surf.cloud.bukkit.command.connection.disconnectPlayerCommand
67
import dev.slne.surf.cloud.bukkit.command.connection.timeoutPlayerCommand
78
import dev.slne.surf.cloud.bukkit.command.lastseen.lastSeenCommand
@@ -38,5 +39,6 @@ class PaperCommandManager : CloudLifecycleAware {
3839
disconnectPlayerCommand()
3940
anticheatBanCommand()
4041
punishCommand()
42+
cloudCommand()
4143
}
4244
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package dev.slne.surf.cloud.bukkit.command.cloud
2+
3+
import dev.jorel.commandapi.kotlindsl.anyExecutor
4+
import dev.jorel.commandapi.kotlindsl.commandTree
5+
import dev.jorel.commandapi.kotlindsl.literalArgument
6+
import dev.slne.surf.cloud.bukkit.permission.CloudPermissionRegistry
7+
import dev.slne.surf.cloud.core.client.config.ClientConfigHolder
8+
import dev.slne.surf.cloud.core.common.util.bean
9+
import dev.slne.surf.surfapi.core.api.messages.adventure.sendText
10+
import org.bukkit.command.CommandSender
11+
12+
fun cloudCommand() = commandTree("cloud") {
13+
withPermission(CloudPermissionRegistry.CLOUD_COMMAND)
14+
15+
literalArgument("reload") {
16+
withPermission(CloudPermissionRegistry.CLOUD_COMMAND_RELOAD)
17+
18+
anyExecutor { sender, _ ->
19+
reload(sender)
20+
}
21+
}
22+
}
23+
24+
private fun reload(sender: CommandSender) {
25+
bean<ClientConfigHolder>().reloadFromFile()
26+
sender.sendText {
27+
appendPrefix()
28+
success("Cloud configuration reloaded successfully.")
29+
}
30+
}

surf-cloud-bukkit/src/main/kotlin/dev/slne/surf/cloud/bukkit/netty/BukkitNettyManager.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dev.slne.surf.cloud.bukkit.netty
33
import dev.slne.surf.cloud.bukkit.netty.listener.NettyPlayerConnectionBlocker
44
import dev.slne.surf.cloud.core.client.netty.NettyCommonClientManager
55
import dev.slne.surf.cloud.core.client.netty.network.PlatformSpecificPacketListenerExtension
6+
import dev.slne.surf.cloud.core.common.config.AbstractSurfCloudConfigHolder
67
import dev.slne.surf.cloud.core.common.spring.CloudLifecycleAware
78
import dev.slne.surf.surfapi.bukkit.api.event.register
89
import dev.slne.surf.surfapi.bukkit.api.event.unregister
@@ -11,8 +12,10 @@ import org.springframework.stereotype.Component
1112

1213
@Component
1314
@Order(CloudLifecycleAware.NETTY_MANAGER_PRIORITY)
14-
class BukkitNettyManager(platformExtension: PlatformSpecificPacketListenerExtension) :
15-
NettyCommonClientManager(false, platformExtension) {
15+
class BukkitNettyManager(
16+
platformExtension: PlatformSpecificPacketListenerExtension,
17+
configHolder: AbstractSurfCloudConfigHolder<*>
18+
) : NettyCommonClientManager(false, platformExtension, configHolder) {
1619

1720
override fun blockPlayerConnections() {
1821
NettyPlayerConnectionBlocker.register()

surf-cloud-bukkit/src/main/kotlin/dev/slne/surf/cloud/bukkit/permission/CloudPermissionRegistry.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ object CloudPermissionRegistry: PermissionRegistry() {
1919
val TIMEOUT_COMMAND = create("$COMMAND_PREFIX.timeout")
2020
val ANTICHEAT_BAN_COMMAND = create("$COMMAND_PREFIX.acban")
2121
val PUNISH_COMMAND = create("$COMMAND_PREFIX.punish")
22+
23+
val CLOUD_COMMAND = create("$COMMAND_PREFIX.cloud")
24+
val CLOUD_COMMAND_RELOAD = create("$CLOUD_COMMAND.reload")
2225
}
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
package dev.slne.surf.cloud.core.client.config
22

3-
import dev.slne.surf.cloud.core.common.coreCloudInstance
4-
import dev.slne.surf.surfapi.core.api.config.createSpongeYmlConfig
5-
import dev.slne.surf.surfapi.core.api.config.surfConfigApi
3+
import dev.slne.surf.cloud.core.common.config.AbstractSurfCloudConfig
4+
import dev.slne.surf.cloud.core.common.config.AbstractSurfCloudConfigHolder
5+
import dev.slne.surf.cloud.core.common.config.ConfigReloadAware
66
import org.spongepowered.configurate.objectmapping.ConfigSerializable
77
import org.spongepowered.configurate.objectmapping.meta.Comment
88
import org.spongepowered.configurate.objectmapping.meta.Setting
9-
10-
val clientConfig: ClientConfig by lazy {
11-
surfConfigApi.createSpongeYmlConfig<ClientConfig>(coreCloudInstance.dataFolder, "client-config.yml")
12-
}
9+
import org.springframework.beans.factory.ObjectProvider
10+
import org.springframework.stereotype.Component
1311

1412
@ConfigSerializable
15-
data class ClientConfig(
16-
13+
class ClientConfig(
1714
@Comment("Whether this server is considered as a lobby server.")
1815
@Setting("isLobby")
1916
val isLobby: Boolean = false,
20-
)
17+
) : AbstractSurfCloudConfig()
18+
19+
@Component
20+
class ClientConfigHolder(reloadAware: ObjectProvider<ConfigReloadAware>) :
21+
AbstractSurfCloudConfigHolder<ClientConfig>(reloadAware, ClientConfig::class.java)

surf-cloud-core/surf-cloud-core-client/src/main/kotlin/dev/slne/surf/cloud/core/client/netty/ClientNettyClientImpl.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import dev.slne.surf.cloud.api.common.netty.network.protocol.PacketFlow
77
import dev.slne.surf.cloud.api.common.netty.packet.NettyPacket
88
import dev.slne.surf.cloud.api.common.netty.packet.RespondingNettyPacket
99
import dev.slne.surf.cloud.api.common.server.CloudServerConstants
10-
import dev.slne.surf.cloud.core.client.config.clientConfig
10+
import dev.slne.surf.cloud.core.client.config.ClientConfigHolder
1111
import dev.slne.surf.cloud.core.client.netty.network.ClientHandshakePacketListenerImpl
1212
import dev.slne.surf.cloud.core.client.netty.network.ClientRunningPacketListenerImpl
1313
import dev.slne.surf.cloud.core.client.netty.network.PlatformSpecificPacketListenerExtension
1414
import dev.slne.surf.cloud.core.client.netty.network.StatusUpdate
1515
import dev.slne.surf.cloud.core.client.server.serverManagerImpl
16-
import dev.slne.surf.cloud.core.common.config.cloudConfig
16+
import dev.slne.surf.cloud.core.common.config.AbstractSurfCloudConfigHolder
1717
import dev.slne.surf.cloud.core.common.coroutines.ConnectionTickScope
1818
import dev.slne.surf.cloud.core.common.data.CloudPersistentData
1919
import dev.slne.surf.cloud.core.common.netty.CommonNettyClientImpl
@@ -39,6 +39,7 @@ import kotlin.time.Duration.Companion.seconds
3939
class ClientNettyClientImpl(
4040
val proxy: Boolean,
4141
val platformExtension: PlatformSpecificPacketListenerExtension,
42+
private val configHolder: AbstractSurfCloudConfigHolder<*>
4243
) : CommonNettyClientImpl(
4344
CloudPersistentData.SERVER_ID,
4445
CloudProperties.SERVER_CATEGORY,
@@ -67,7 +68,7 @@ class ClientNettyClientImpl(
6768
* Bootstraps the client. Setup the connection protocol until the PreRunning state.
6869
*/
6970
suspend fun bootstrap() {
70-
val config = cloudConfig.connectionConfig.nettyConfig
71+
val config = configHolder.config.connectionConfig.nettyConfig
7172
connectToServer(ServerAddress(config.host, config.port))
7273
preRunningCallback.await() // Wait until the connection is in the PreRunning state
7374
}
@@ -89,7 +90,7 @@ class ClientNettyClientImpl(
8990
val connection = ConnectionImpl(PacketFlow.CLIENTBOUND, EncryptionManager.instance)
9091
ConnectionImpl.connect(
9192
inetSocketAddress,
92-
cloudConfig.connectionConfig.nettyConfig.useEpoll,
93+
configHolder.config.connectionConfig.nettyConfig.useEpoll,
9394
connection
9495
)
9596

@@ -122,7 +123,7 @@ class ClientNettyClientImpl(
122123
serverCategory,
123124
serverName,
124125
proxy,
125-
clientConfig.isLobby,
126+
(configHolder as ClientConfigHolder).config.isLobby,
126127
)
127128
)
128129
} catch (e: Exception) {

surf-cloud-core/surf-cloud-core-client/src/main/kotlin/dev/slne/surf/cloud/core/client/netty/NettyCommonClientManager.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dev.slne.surf.cloud.core.client.netty
33
import dev.slne.surf.cloud.api.common.util.TimeLogger
44
import dev.slne.surf.cloud.core.client.netty.network.PlatformSpecificPacketListenerExtension
55
import dev.slne.surf.cloud.core.common.CloudCoreInstance
6+
import dev.slne.surf.cloud.core.common.config.AbstractSurfCloudConfigHolder
67
import dev.slne.surf.cloud.core.common.coroutines.CloudConnectionVerificationScope
78
import dev.slne.surf.cloud.core.common.netty.NettyManager
89
import dev.slne.surf.surfapi.core.api.util.logger
@@ -14,9 +15,10 @@ import kotlin.time.Duration.Companion.minutes
1415

1516
abstract class NettyCommonClientManager(
1617
val proxy: Boolean,
17-
val platformExtension: PlatformSpecificPacketListenerExtension
18+
val platformExtension: PlatformSpecificPacketListenerExtension,
19+
private val configHolder: AbstractSurfCloudConfigHolder<*>
1820
) : NettyManager() {
19-
val nettyClient by lazy { ClientNettyClientImpl(proxy, platformExtension) }
21+
val nettyClient by lazy { ClientNettyClientImpl(proxy, platformExtension, configHolder) }
2022

2123
override suspend fun onBootstrap(
2224
data: CloudCoreInstance.BootstrapData,

surf-cloud-core/surf-cloud-core-client/src/main/kotlin/dev/slne/surf/cloud/core/client/netty/network/ClientEncryptionManager.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package dev.slne.surf.cloud.core.client.netty.network
22

33
import com.google.auto.service.AutoService
4-
import dev.slne.surf.cloud.core.common.config.cloudConfig
4+
import dev.slne.surf.cloud.core.common.config.AbstractSurfCloudConfigHolder
55
import dev.slne.surf.cloud.core.common.netty.network.EncryptionManager
66
import dev.slne.surf.cloud.core.common.netty.network.HandlerNames
7-
import dev.slne.surf.surfapi.core.api.util.logger
7+
import dev.slne.surf.cloud.core.common.util.bean
88
import io.netty.channel.Channel
99
import io.netty.handler.ssl.SslContext
1010
import io.netty.handler.ssl.SslContextBuilder
@@ -20,7 +20,7 @@ class ClientEncryptionManager : EncryptionManager() {
2020
private val trustManagerFile = (certificatesFolder / "ca.crt").toFile()
2121

2222
override fun setupEncryption(ch: Channel) {
23-
val config = cloudConfig.connectionConfig.nettyConfig
23+
val config = bean<AbstractSurfCloudConfigHolder<*>>().config.connectionConfig.nettyConfig
2424
ch.pipeline().addFirst(
2525
HandlerNames.SSL_HANDLER,
2626
sslContext.newHandler(ch.alloc(), config.host, config.port)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@file:Internal
2+
3+
package dev.slne.surf.cloud.core.common.config
4+
5+
import dev.slne.surf.cloud.api.common.util.forEachAnnotationOrdered
6+
import dev.slne.surf.cloud.core.common.config.connection.ConnectionConfig
7+
import dev.slne.surf.cloud.core.common.config.logging.LoggingConfig
8+
import dev.slne.surf.cloud.core.common.coreCloudInstance
9+
import dev.slne.surf.surfapi.core.api.config.manager.SpongeConfigManager
10+
import dev.slne.surf.surfapi.core.api.config.surfConfigApi
11+
import org.jetbrains.annotations.ApiStatus.Internal
12+
import org.spongepowered.configurate.objectmapping.meta.Comment
13+
import org.spongepowered.configurate.objectmapping.meta.Setting
14+
import org.springframework.beans.factory.ObjectProvider
15+
16+
abstract class AbstractSurfCloudConfig(
17+
@Comment("Config for various connections")
18+
@Setting("connection")
19+
val connectionConfig: ConnectionConfig = ConnectionConfig(),
20+
21+
@Comment("Config for logging")
22+
@Setting("logging")
23+
val logging: LoggingConfig = LoggingConfig()
24+
)
25+
26+
abstract class AbstractSurfCloudConfigHolder<C : AbstractSurfCloudConfig>(
27+
private val reloadAware: ObjectProvider<ConfigReloadAware>,
28+
configClass: Class<C>
29+
) {
30+
private val manager: SpongeConfigManager<C>
31+
32+
init {
33+
surfConfigApi.createSpongeYmlConfig(
34+
configClass,
35+
coreCloudInstance.dataFolder,
36+
"config.yml"
37+
)
38+
39+
manager = surfConfigApi.getSpongeConfigManagerForConfig(configClass)
40+
}
41+
42+
val config: C
43+
get() = manager.config
44+
45+
46+
fun reloadFromFile() {
47+
reloadAware.forEachAnnotationOrdered { it.beforeReload() }
48+
manager.reloadFromFile()
49+
reloadAware.forEachAnnotationOrdered { it.afterReload() }
50+
}
51+
52+
fun saveToFile() {
53+
reloadAware.forEachAnnotationOrdered { it.beforeSave() }
54+
manager.save()
55+
}
56+
}

surf-cloud-standalone/src/main/kotlin/dev/slne/surf/cloud/standalone/config/ConfigReloadAware.kt renamed to surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/config/ConfigReloadAware.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
package dev.slne.surf.cloud.standalone.config
1+
package dev.slne.surf.cloud.core.common.config
22

33
import org.springframework.stereotype.Component
44

55
@Component
66
interface ConfigReloadAware {
77
fun beforeReload() = Unit
88
fun afterReload() = Unit
9+
10+
fun beforeSave() = Unit
911
}

0 commit comments

Comments
 (0)