@@ -15,9 +15,12 @@ import kotlinx.coroutines.withTimeout
15
15
import net.kyori.adventure.text.Component
16
16
import net.kyori.adventure.text.format.NamedTextColor
17
17
import net.minestom.server.MinecraftServer
18
+ import net.minestom.server.ServerFlag
18
19
import net.minestom.server.event.Event
19
20
import net.minestom.server.event.EventNode
20
21
import net.minestom.server.event.player.AsyncPlayerConfigurationEvent
22
+ import net.minestom.server.network.ConnectionState
23
+ import net.minestom.server.timer.TaskSchedule
21
24
22
25
object InitialInstanceRouter : Bootstrap(EnvType .PRODUCTION ) {
23
26
@@ -27,6 +30,8 @@ object InitialInstanceRouter : Bootstrap(EnvType.PRODUCTION) {
27
30
Component .text(" Couldn't find which world to put you in! (Destination not ready)" , NamedTextColor .RED )
28
31
private val HANDSHAKE_FAILED =
29
32
Component .text(" Couldn't find which world to put you in! (Handshake failed)" , NamedTextColor .RED )
33
+ private val LOAD_TIMED_OUT =
34
+ Component .text(" There was a problem joining the server! (Configuration timed out)" , NamedTextColor .RED )
30
35
internal val DATA_LOAD_FAILED =
31
36
Component .text(" Failed to load your player data!" , NamedTextColor .RED )
32
37
@@ -104,8 +109,21 @@ object InitialInstanceRouter : Bootstrap(EnvType.PRODUCTION) {
104
109
game.getModule<SpawnpointModule >().spawnpointProvider.getSpawnpoint(event.player)
105
110
}
106
111
107
- MinecraftServer .getSchedulerManager().scheduleNextTick {
108
- game.addPlayer(event.player, sendPlayer = false )
112
+
113
+ var ticks = 0
114
+
115
+ // Wait up to 10 seconds for the player to enter the PLAY phase and then add them to the game.
116
+ MinecraftServer .getSchedulerManager().submitTask {
117
+ ticks ++
118
+ if (event.player.playerConnection.connectionState == ConnectionState .PLAY ) {
119
+ game.addPlayer(event.player, sendPlayer = false )
120
+ return @submitTask TaskSchedule .stop()
121
+ } else if (ticks < ServerFlag .SERVER_TICKS_PER_SECOND * 10 ) {
122
+ return @submitTask TaskSchedule .nextTick()
123
+ } else {
124
+ event.player.kick(LOAD_TIMED_OUT )
125
+ return @submitTask TaskSchedule .stop()
126
+ }
109
127
}
110
128
111
129
Messaging .IO .launch {
0 commit comments