From 8b5bb0dbe060448cac780c3d4417dbe78c421b3d Mon Sep 17 00:00:00 2001 From: Aikar Date: Thu, 9 Jul 2020 19:24:10 -0400 Subject: [PATCH] Misc Improvements to Async Teleporting and Light patch Stop light copy was missing a default in the impl. Should of been extremely low chance of impacting anything though as the very first copy operation would have fixed it. Sadly this doesn't fix the issues weve been trying to fix. Fix player async teleporting adding priority to wrong world for cross world teleports Also improve teleporting to wait for entity ticking status before teleporting to prevent neighbors loading --- .../Asynchronous-chunk-IO-and-loading.patch | 39 +++++++++++++++++++ ...k-Priority-Urgency-System-for-Chunks.patch | 4 +- ...te-operations-for-updating-light-dat.patch | 6 ++- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/Spigot-Server-Patches/Asynchronous-chunk-IO-and-loading.patch b/Spigot-Server-Patches/Asynchronous-chunk-IO-and-loading.patch index 53ce84e8ff..a4f2fbaa8c 100644 --- a/Spigot-Server-Patches/Asynchronous-chunk-IO-and-loading.patch +++ b/Spigot-Server-Patches/Asynchronous-chunk-IO-and-loading.patch @@ -3079,6 +3079,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @@ -0,0 +0,0 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { } + @Nullable +- protected PlayerChunk getUpdatingChunk(long i) { ++ public PlayerChunk getUpdatingChunk(long i) { // Paper + return (PlayerChunk) this.updatingChunks.get(i); + } + @Nullable - protected PlayerChunk getVisibleChunk(long i) { + public PlayerChunk getVisibleChunk(long i) { // Paper - protected -> public @@ -4076,6 +4082,39 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 // Spigot start @Override +diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +@@ -0,0 +0,0 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { + entity.setHeadRotation(yaw); + } + ++ @Override// Paper start ++ public java.util.concurrent.CompletableFuture teleportAsync(Location loc, @javax.annotation.Nonnull org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) { ++ net.minecraft.server.PlayerChunkMap playerChunkMap = ((CraftWorld) loc.getWorld()).getHandle().getChunkProvider().playerChunkMap; ++ java.util.concurrent.CompletableFuture future = new java.util.concurrent.CompletableFuture<>(); ++ ++ loc.getWorld().getChunkAtAsyncUrgently(loc).thenCompose(chunk -> { ++ net.minecraft.server.ChunkCoordIntPair pair = new net.minecraft.server.ChunkCoordIntPair(chunk.getX(), chunk.getZ()); ++ ((CraftWorld) loc.getWorld()).getHandle().getChunkProvider().addTicketAtLevel(net.minecraft.server.TicketType.POST_TELEPORT, pair, 31, 0); ++ net.minecraft.server.PlayerChunk updatingChunk = playerChunkMap.getUpdatingChunk(pair.pair()); ++ if (updatingChunk != null) { ++ return updatingChunk.getEntityTickingFuture(); ++ } else { ++ return java.util.concurrent.CompletableFuture.completedFuture(com.mojang.datafixers.util.Either.left(((org.bukkit.craftbukkit.CraftChunk)chunk).getHandle())); ++ } ++ }).thenAccept((chunk) -> future.complete(teleport(loc, cause))).exceptionally(ex -> { ++ future.completeExceptionally(ex); ++ return null; ++ }); ++ return future; ++ } ++ // Paper end ++ + @Override + public boolean teleport(Location location) { + return teleport(location, TeleportCause.PLUGIN); diff --git a/src/main/java/org/spigotmc/WatchdogThread.java b/src/main/java/org/spigotmc/WatchdogThread.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/spigotmc/WatchdogThread.java diff --git a/Spigot-Server-Patches/Implement-Chunk-Priority-Urgency-System-for-Chunks.patch b/Spigot-Server-Patches/Implement-Chunk-Priority-Urgency-System-for-Chunks.patch index 7d5081bb93..167f513bb0 100644 --- a/Spigot-Server-Patches/Implement-Chunk-Priority-Urgency-System-for-Chunks.patch +++ b/Spigot-Server-Patches/Implement-Chunk-Priority-Urgency-System-for-Chunks.patch @@ -1232,8 +1232,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start + @Override -+ public java.util.concurrent.CompletableFuture teleportAsync(Location loc, PlayerTeleportEvent.TeleportCause cause) { -+ getHandle().getWorldServer().getChunkProvider().markAreaHighPriority(new net.minecraft.server.ChunkCoordIntPair(net.minecraft.server.MathHelper.floor(loc.getX()) >> 4, net.minecraft.server.MathHelper.floor(loc.getZ()) >> 4), 28, 3); // Paper - load area high priority ++ public java.util.concurrent.CompletableFuture teleportAsync(Location loc, @javax.annotation.Nonnull PlayerTeleportEvent.TeleportCause cause) { ++ ((CraftWorld)loc.getWorld()).getHandle().getChunkProvider().markAreaHighPriority(new net.minecraft.server.ChunkCoordIntPair(net.minecraft.server.MathHelper.floor(loc.getX()) >> 4, net.minecraft.server.MathHelper.floor(loc.getZ()) >> 4), 28, 3); // Paper - load area high priority + return super.teleportAsync(loc, cause); + } + // Paper end diff --git a/Spigot-Server-Patches/Stop-copy-on-write-operations-for-updating-light-dat.patch b/Spigot-Server-Patches/Stop-copy-on-write-operations-for-updating-light-dat.patch index 259bed829d..bfe46d3ee4 100644 --- a/Spigot-Server-Patches/Stop-copy-on-write-operations-for-updating-light-dat.patch +++ b/Spigot-Server-Patches/Stop-copy-on-write-operations-for-updating-light-dat.patch @@ -293,16 +293,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 private int b; - private final Long2IntOpenHashMap c; -+ private final com.destroystokyo.paper.util.map.QueuedChangesMapLong2Int otherData; // Paper - avoid copying light data - +- - public a(Long2ObjectOpenHashMap long2objectopenhashmap, Long2IntOpenHashMap long2intopenhashmap, int i) { - super(long2objectopenhashmap); - this.c = long2intopenhashmap; - long2intopenhashmap.defaultReturnValue(i); ++ private final com.destroystokyo.paper.util.map.QueuedChangesMapLong2Int otherData; // Paper - avoid copying light data ++ + // Paper start - avoid copying light data + public a(com.destroystokyo.paper.util.map.QueuedChangesMapLong2Object data, com.destroystokyo.paper.util.map.QueuedChangesMapLong2Int otherData, int i, boolean isVisible) { + super(data, isVisible); + this.otherData = otherData; ++ otherData.queueDefaultReturnValue(i); + // Paper end - avoid copying light data this.b = i; }