@@ -12620,7 +12620,7 @@ index b8a4b4cc02a2fc6b70f4b840796eed501aad6239..0bf2173c5445de021090c2d0264afc44
1262012620
1262112621 // Paper start - add proper async disconnect
1262212622diff --git a/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java b/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java
12623- index a3645322be006d5501fa7fb8944509a9c6b58e32..78db6eb8567f6495e0c5dc474589e47a3043976a 100644
12623+ index a3645322be006d5501fa7fb8944509a9c6b58e32..2cc3dd1f267ae78d3aacb84509d4bf668235688f 100644
1262412624--- a/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java
1262512625+++ b/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java
1262612626@@ -53,6 +53,7 @@ public class ServerConfigurationPacketListenerImpl extends ServerCommonPacketLis
@@ -12650,8 +12650,8 @@ index a3645322be006d5501fa7fb8944509a9c6b58e32..78db6eb8567f6495e0c5dc474589e47a
1265012650+
1265112651+ this.switchToMain = serverPlayer;
1265212652+ // now the connection responsibility is transferred to the region
12653- + final net.minecraft.server.level.ServerLevel world = serverPlayer.level ();
12654- + final net.minecraft.world.level.ChunkPos chunkPos = serverPlayer.chunkPosition( );
12653+ + final net.minecraft.server.level.ServerLevel world = this.prepareSpawnTask.getSpawnWorld ();
12654+ + final net.minecraft.world.level.ChunkPos chunkPos = new net.minecraft.world.level.ChunkPos(net.minecraft.core.BlockPos.containing(this.prepareSpawnTask.getSpawnPosition()) );
1265512655+ world.moonrise$getChunkTaskScheduler().scheduleTickingState(
1265612656+ chunkPos.x, chunkPos.z, net.minecraft.server.level.FullChunkStatus.ENTITY_TICKING, true,
1265712657+ ca.spottedleaf.concurrentutil.util.Priority.HIGHER,
@@ -13142,10 +13142,10 @@ index 31bc0a105152a7f24a4126542bea7dbebc3e037c..ce40fda2f6174602d53d46e860e87cf0
1314213142 if (asyncEvent.getResult() != PlayerPreLoginEvent.Result.ALLOWED) {
1314313143 event.disallow(asyncEvent.getResult(), asyncEvent.kickMessage()); // Paper - Adventure
1314413144diff --git a/net/minecraft/server/network/config/PrepareSpawnTask.java b/net/minecraft/server/network/config/PrepareSpawnTask.java
13145- index 5014840bf5d7ef53a4fea8aa6f3b25eb4033ff96..2cfbe6c119fcd7379bfea04920eef29b6b4f0312 100644
13145+ index 5014840bf5d7ef53a4fea8aa6f3b25eb4033ff96..1fd5a68fcb685646c5c28c8e94ffef5eb319d7d8 100644
1314613146--- a/net/minecraft/server/network/config/PrepareSpawnTask.java
1314713147+++ b/net/minecraft/server/network/config/PrepareSpawnTask.java
13148- @@ -107,9 +107,20 @@ public class PrepareSpawnTask implements ConfigurationTask {
13148+ @@ -107,9 +107,24 @@ public class PrepareSpawnTask implements ConfigurationTask {
1314913149 }
1315013150 final ServerLevel serverLevel = serverLevel1;
1315113151 // Paper end - move logic in Entity to here, to use bukkit supplied world UUID & reset to main world spawn if no valid world is found
@@ -13154,44 +13154,64 @@ index 5014840bf5d7ef53a4fea8aa6f3b25eb4033ff96..2cfbe6c119fcd7379bfea04920eef29b
1315413154- .orElseGet(() -> PlayerSpawnFinder.findSpawn(serverLevel, respawnData.pos()));
1315513155+ // Folia start - region threading
1315613156+ CompletableFuture<Vec3> completableFuture = new java.util.concurrent.CompletableFuture<>();
13157- + ca.spottedleaf.concurrentutil.completable.CallbackCompletable<org.bukkit.Location> spawnComplete = new ca.spottedleaf.concurrentutil.completable.CallbackCompletable<>();
13158- + spawnComplete.addWaiter(
13159- + (final org.bukkit.Location loc, final Throwable throwable) -> {
13160- + if (throwable != null) {
13161- + completableFuture.completeExceptionally(throwable);
13162- + } else {
13163- + completableFuture.complete(io.papermc.paper.util.MCUtil.toVec3(loc));
13157+ + if (savedPosition.position().isPresent()) {
13158+ + completableFuture.complete(savedPosition.position().get());
13159+ + } else {
13160+ + ca.spottedleaf.concurrentutil.completable.CallbackCompletable<org.bukkit.Location> spawnComplete = new ca.spottedleaf.concurrentutil.completable.CallbackCompletable<>();
13161+ + spawnComplete.addWaiter(
13162+ + (final org.bukkit.Location loc, final Throwable throwable) -> {
13163+ + if (throwable != null) {
13164+ + completableFuture.completeExceptionally(throwable);
13165+ + } else {
13166+ + completableFuture.complete(io.papermc.paper.util.MCUtil.toVec3(loc));
13167+ + }
1316413168+ }
13165- + }
13166- + );
13167- + ServerPlayer.fudgeSpawnLocation(serverLevel, spawnComplete);
13169+ + );
13170+ + ServerPlayer.fudgeSpawnLocation(serverLevel, spawnComplete );
13171+ + }
1316813172+ // Folia end - region threading
1316913173 Vec2 vec2 = savedPosition.rotation().orElse(new Vec2(respawnData.yaw(), respawnData.pitch()));
1317013174 this.state = new PrepareSpawnTask.Preparing(serverLevel, completableFuture, vec2);
1317113175 }
13172- @@ -133,9 +144,19 @@ public class PrepareSpawnTask implements ConfigurationTask {
13176+ @@ -133,9 +148,35 @@ public class PrepareSpawnTask implements ConfigurationTask {
1317313177 };
1317413178 }
1317513179
1317613180- public ServerPlayer spawnPlayer(Connection connection, CommonListenerCookie cookie) {
1317713181+ // Folia start - region threading
13178- + public ServerPlayer createPlayer(Connection connection, CommonListenerCookie cookie ) { // Folia - region threading
13182+ + public ServerLevel getSpawnWorld( ) {
1317913183+ if (this.state instanceof PrepareSpawnTask.Ready ready) {
13180- + return ready.createPlayer(connection, cookie); // Folia - region threading
13184+ + return ready.getSpawnWorld();
1318113185+ } else {
1318213186+ throw new IllegalStateException("Player spawn was not ready");
1318313187+ }
1318413188+ }
13185- + // Folia end - region threading
1318613189+
13187- + public ServerPlayer spawnPlayer(Connection connection, CommonListenerCookie cookie, ServerPlayer serverPlayer) { // Folia - region threading
13190+ + public Vec3 getSpawnPosition() {
13191+ + if (this.state instanceof PrepareSpawnTask.Ready ready) {
13192+ + return ready.getSpawnPosition();
13193+ + } else {
13194+ + throw new IllegalStateException("Player spawn was not ready");
13195+ + }
13196+ + }
13197+ +
13198+ + public ServerPlayer createPlayer(Connection connection, CommonListenerCookie cookie) {
1318813199 if (this.state instanceof PrepareSpawnTask.Ready ready) {
1318913200- return ready.spawn(connection, cookie);
13201+ + return ready.createPlayer(connection, cookie);
13202+ + } else {
13203+ + throw new IllegalStateException("Player spawn was not ready");
13204+ + }
13205+ + }
13206+ + // Folia end - region threading
13207+ +
13208+ + public ServerPlayer spawnPlayer(Connection connection, CommonListenerCookie cookie, ServerPlayer serverPlayer) { // Folia - region threading
13209+ + if (this.state instanceof PrepareSpawnTask.Ready ready) {
1319013210+ return ready.spawn(connection, cookie, serverPlayer); // Folia - region threading
1319113211 } else {
1319213212 throw new IllegalStateException("Player spawn was not ready");
1319313213 }
13194- @@ -185,7 +206 ,7 @@ public class PrepareSpawnTask implements ConfigurationTask {
13214+ @@ -185,7 +226 ,7 @@ public class PrepareSpawnTask implements ConfigurationTask {
1319513215 Vec3 vec3 = this.spawnPosition.join();
1319613216 if (this.chunkLoadFuture == null) {
1319713217 // Paper start - PlayerSpawnLocationEvent
@@ -13200,22 +13220,30 @@ index 5014840bf5d7ef53a4fea8aa6f3b25eb4033ff96..2cfbe6c119fcd7379bfea04920eef29b
1320013220 ServerPlayer serverPlayer;
1320113221 if (PrepareSpawnTask.this.listener.connection.savedPlayerForLegacyEvents != null) {
1320213222 serverPlayer = PrepareSpawnTask.this.listener.connection.savedPlayerForLegacyEvents;
13203- @@ -261,9 +282,11 @@ public class PrepareSpawnTask implements ConfigurationTask {
13223+ @@ -261,9 +302,19 @@ public class PrepareSpawnTask implements ConfigurationTask {
1320413224 this.spawnLevel.getChunkSource().addTicketWithRadius(TicketType.PLAYER_SPAWN, new ChunkPos(BlockPos.containing(this.spawnPosition)), 3);
1320513225 }
1320613226
1320713227- public ServerPlayer spawn(Connection connection, CommonListenerCookie cookie) {
1320813228- ChunkPos chunkPos = new ChunkPos(BlockPos.containing(this.spawnPosition));
1320913229- this.spawnLevel.waitForEntities(chunkPos, 3);
1321013230+ // Folia start - region threading
13231+ + public ServerLevel getSpawnWorld() {
13232+ + return this.spawnLevel;
13233+ + }
13234+ +
13235+ + public Vec3 getSpawnPosition() {
13236+ + return this.spawnPosition;
13237+ + }
13238+ +
1321113239+ public ServerPlayer createPlayer(Connection connection, CommonListenerCookie cookie) {
1321213240+ //ChunkPos chunkPos = new ChunkPos(BlockPos.containing(this.spawnPosition));
1321313241+ //this.spawnLevel.waitForEntities(chunkPos, 3);
1321413242+ // Folia end - region threading
1321513243 // Paper start - configuration api - possibly use legacy saved server player instance
1321613244 ServerPlayer serverPlayer;
1321713245 if (connection.savedPlayerForLegacyEvents != null) {
13218- @@ -277,6 +300 ,11 @@ public class PrepareSpawnTask implements ConfigurationTask {
13246+ @@ -277,6 +328 ,11 @@ public class PrepareSpawnTask implements ConfigurationTask {
1321913247 serverPlayer = new ServerPlayer(PrepareSpawnTask.this.server, this.spawnLevel, cookie.gameProfile(), cookie.clientInformation());
1322013248 }
1322113249 // Paper end - configuration api - possibly use legacy saved server player instance
0 commit comments