Skip to content

Commit e58a46a

Browse files
committed
refactor: modularize lobby project by introducing surf-lobby-core, simplify lifecycle management, and update dependencies
1 parent 8287aee commit e58a46a

File tree

34 files changed

+309
-208
lines changed

34 files changed

+309
-208
lines changed

.idea/codeStyles/Project.xml

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

.idea/compiler.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

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

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ buildscript {
44
maven("https://repo.slne.dev/repository/maven-public/") { name = "maven-public" }
55
}
66
dependencies {
7-
classpath("dev.slne.surf:surf-api-gradle-plugin:1.21.7+")
7+
classpath("dev.slne.surf:surf-api-gradle-plugin:1.21.8+")
88
}
99
}
1010

settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ rootProject.name = "surf-lobby"
44
include(":surf-lobby-paper:surf-lobby-paper-common")
55
include(":surf-lobby-paper:surf-lobby-paper-server")
66
include(":surf-lobby-paper:surf-lobby-paper-lobby")
7+
8+
include("surf-lobby-core")

surf-lobby-core/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
id("dev.slne.surf.surfapi.gradle.core")
3+
}
4+
5+
surfCoreApi {
6+
withCloudCommon()
7+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package dev.slne.surf.lobby
2+
3+
import dev.slne.surf.cloud.api.common.CloudInstance
4+
import dev.slne.surf.cloud.api.common.SurfCloudApplication
5+
import dev.slne.surf.cloud.api.common.startSpringApplication
6+
import org.springframework.context.ConfigurableApplicationContext
7+
8+
@SurfCloudApplication
9+
class LobbyApplication {
10+
companion object {
11+
lateinit var context: ConfigurableApplicationContext
12+
13+
fun start() {
14+
context = CloudInstance.startSpringApplication(LobbyApplication::class)
15+
}
16+
17+
fun stop() {
18+
if (::context.isInitialized) {
19+
context.close()
20+
}
21+
}
22+
}
23+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package dev.slne.surf.lobby.core
2+
3+
import dev.slne.surf.lobby.LobbyApplication
4+
import dev.slne.surf.lobby.core.lifecycle.LobbyLifecycleHandler
5+
import org.springframework.beans.factory.getBean
6+
7+
object LobbyInstance {
8+
private val lifecycleHandler get() = LobbyApplication.context.getBean<LobbyLifecycleHandler>()
9+
10+
fun onBootstrap() {
11+
LobbyApplication.start()
12+
lifecycleHandler.onBootstrap()
13+
}
14+
15+
suspend fun onLoad() {
16+
lifecycleHandler.onLoad()
17+
}
18+
19+
suspend fun onEnable() {
20+
lifecycleHandler.onEnable()
21+
}
22+
23+
suspend fun onDisable() {
24+
lifecycleHandler.onDisable()
25+
LobbyApplication.stop()
26+
}
27+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package dev.slne.surf.lobby.core.lifecycle
2+
3+
interface LobbyLifecycle {
4+
fun onBootstrap() = Unit
5+
suspend fun onLoad() = Unit
6+
suspend fun onEnable() = Unit
7+
suspend fun onDisable() = Unit
8+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package dev.slne.surf.lobby.core.lifecycle
2+
3+
import dev.slne.surf.cloud.api.common.util.forEachAnnotationOrdered
4+
import dev.slne.surf.cloud.api.common.util.forEachAnnotationOrderedReversed
5+
import dev.slne.surf.lobby.core.lifecycle.LobbyLifecycle
6+
import org.springframework.beans.factory.ObjectProvider
7+
import org.springframework.stereotype.Component
8+
9+
@Component
10+
class LobbyLifecycleHandler(private val lifecycles: ObjectProvider<LobbyLifecycle>) {
11+
12+
fun onBootstrap() {
13+
lifecycles.forEachAnnotationOrdered { it.onBootstrap() }
14+
}
15+
16+
suspend fun onLoad() {
17+
lifecycles.forEachAnnotationOrdered { it.onLoad() }
18+
}
19+
20+
suspend fun onEnable() {
21+
lifecycles.forEachAnnotationOrdered { it.onEnable() }
22+
}
23+
24+
suspend fun onDisable() {
25+
lifecycles.forEachAnnotationOrderedReversed { it.onDisable() }
26+
}
27+
}

0 commit comments

Comments
 (0)