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

Commit da39cd1

Browse files
committed
feat(proxy): refactor PrePlayerJoinTaskManager to use object instead of class and simplify task registration
1 parent 8f02d24 commit da39cd1

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import dev.slne.surf.cloud.core.common.netty.network.protocol.running.*
2424
import dev.slne.surf.cloud.core.common.netty.registry.listener.NettyListenerRegistry
2525
import dev.slne.surf.cloud.core.common.player.playerManagerImpl
2626
import dev.slne.surf.cloud.core.common.player.task.PrePlayerJoinTaskManager
27-
import dev.slne.surf.cloud.core.common.util.bean
2827
import dev.slne.surf.cloud.core.common.util.hasPermissionPlattform
2928
import dev.slne.surf.surfapi.core.api.messages.adventure.getPointer
3029
import dev.slne.surf.surfapi.core.api.messages.adventure.text
@@ -280,7 +279,7 @@ class ClientRunningPacketListenerImpl(
280279

281280
override suspend fun handleRunPlayerPreJoinTasks(packet: ClientboundRunPrePlayerJoinTasksPacket) {
282281
val player = commonPlayerManagerImpl.getOfflinePlayer(packet.uuid)
283-
val result = bean<PrePlayerJoinTaskManager>().runTasks(player)
282+
val result = PrePlayerJoinTaskManager.runTasks(player)
284283
packet.respond(RunPrePlayerJoinTasksResultPacket(result))
285284
}
286285

surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/player/task/PrePlayerJoinTaskAutoRegistrationHandler.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,26 @@ import org.springframework.context.SmartLifecycle
77
import org.springframework.stereotype.Component
88

99
@Component
10-
class PrePlayerJoinTaskAutoRegistrationHandler(private val taskManager: PrePlayerJoinTaskManager) :
11-
BeanPostProcessor, SmartLifecycle {
10+
class PrePlayerJoinTaskAutoRegistrationHandler : BeanPostProcessor, SmartLifecycle {
1211
private val watched = mutableObjectSetOf<PrePlayerJoinTask>()
1312
private var running = false
1413

1514
override fun postProcessAfterInitialization(bean: Any, beanName: String): Any? {
1615
if (bean is PrePlayerJoinTask) {
1716
if (watched.add(bean) && running) {
18-
taskManager.registerTask(bean)
17+
PrePlayerJoinTaskManager.registerTask(bean)
1918
}
2019
}
2120
return bean
2221
}
2322

2423
override fun start() {
25-
taskManager.registerTasks(watched)
24+
PrePlayerJoinTaskManager.registerTasks(watched)
2625
running = true
2726
}
2827

2928
override fun stop() {
30-
watched.forEach { taskManager.unregisterTask(it) }
29+
watched.forEach { PrePlayerJoinTaskManager.unregisterTask(it) }
3130
watched.clear()
3231
running = false
3332
}

surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/player/task/PrePlayerJoinTaskManager.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import org.springframework.core.OrderComparator
1010
import org.springframework.stereotype.Component
1111
import dev.slne.surf.cloud.core.common.coroutines.PrePlayerJoinTaskScope as TaskScope
1212

13-
@Component
14-
class PrePlayerJoinTaskManager : SmartInitializingSingleton {
13+
object PrePlayerJoinTaskManager {
1514
private val log = logger()
1615
private val tasks = mutableObjectListOf<PrePlayerJoinTask>()
1716
private var singletonsInstantiated = false
@@ -42,11 +41,6 @@ class PrePlayerJoinTaskManager : SmartInitializingSingleton {
4241
}
4342
}
4443

45-
override fun afterSingletonsInstantiated() {
46-
singletonsInstantiated = true
47-
maybeSort()
48-
}
49-
5044
suspend fun runTasks(player: CommonOfflineCloudPlayerImpl) = withContext(TaskScope.context) {
5145
for (task in tasks) {
5246
val result = runCatching { task.preJoin(player) }
@@ -63,4 +57,12 @@ class PrePlayerJoinTaskManager : SmartInitializingSingleton {
6357
}
6458
PrePlayerJoinTask.Result.ALLOWED
6559
}
66-
}
60+
61+
@Component
62+
class Lifecycle : SmartInitializingSingleton {
63+
override fun afterSingletonsInstantiated() {
64+
singletonsInstantiated = true
65+
maybeSort()
66+
}
67+
}
68+
}

surf-cloud-standalone/src/main/kotlin/dev/slne/surf/cloud/standalone/player/StandaloneCloudPlayerManagerImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class StandaloneCloudPlayerManagerImpl : CloudPlayerManagerImpl<StandaloneCloudP
4848
}
4949

5050
override suspend fun preJoin(player: StandaloneCloudPlayerImpl): PrePlayerJoinTask.Result {
51-
val serverResult = bean<PrePlayerJoinTaskManager>().runTasks(player)
51+
val serverResult = PrePlayerJoinTaskManager.runTasks(player)
5252
if (serverResult !is PrePlayerJoinTask.Result.ALLOWED) return serverResult
5353
val connections = serverManagerImpl.retrieveAllServers().map { it.connection }
5454

0 commit comments

Comments
 (0)