diff --git a/patches/api/0469-API-for-checking-sent-chunks.patch b/patches/api/0469-API-for-checking-sent-chunks.patch new file mode 100644 index 000000000000..15337cfbd49f --- /dev/null +++ b/patches/api/0469-API-for-checking-sent-chunks.patch @@ -0,0 +1,50 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Flo0 +Date: Mon, 8 Apr 2024 16:22:07 +0200 +Subject: [PATCH] API for checking sent chunks + + +diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java +index c6cb4f17469a8f2e60dd3e28d41402851ce5fb21..9c64601a502a887eab111df41fc96cd2a2786bb7 100644 +--- a/src/main/java/org/bukkit/entity/Player.java ++++ b/src/main/java/org/bukkit/entity/Player.java +@@ -3707,6 +3707,39 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM + void resetIdleDuration(); + // Paper end + ++ // Paper start - Add chunk view API ++ /** ++ * Gets the set of chunk keys for all chunks that have been sent to the player. ++ * ++ * @return unmodifiable view of chunk keys ++ */ ++ @NotNull java.util.Set getSentChunkKeys(); ++ ++ /** ++ * Gets the set of chunks that have been sent to the player. ++ * ++ * @return unmodifiable set of chunks ++ */ ++ @NotNull java.util.Set getSentChunks(); ++ ++ /** ++ * Checks if the player has been sent a specific chunk. ++ * ++ * @param chunk the chunk to check ++ * @return true if the player has been sent the chunk, false otherwise ++ */ ++ boolean isChunkSent(@NotNull org.bukkit.Chunk chunk); ++ ++ /** ++ * Checks if the player has been sent a specific chunk. ++ * @see org.bukkit.Chunk#getChunkKey() ++ * ++ * @param chunkKey the chunk key to check ++ * @return true if the player has been sent the chunk, false otherwise ++ */ ++ boolean isChunkKeySent(long chunkKey); ++ // Paper end ++ + @NotNull + @Override + Spigot spigot(); diff --git a/patches/server/1055-API-for-checking-sent-chunks.patch b/patches/server/1055-API-for-checking-sent-chunks.patch new file mode 100644 index 000000000000..6925844e7c31 --- /dev/null +++ b/patches/server/1055-API-for-checking-sent-chunks.patch @@ -0,0 +1,69 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Flo0 +Date: Mon, 8 Apr 2024 16:43:16 +0200 +Subject: [PATCH] API for checking sent chunks + + +diff --git a/src/main/java/io/papermc/paper/chunk/system/RegionizedPlayerChunkLoader.java b/src/main/java/io/papermc/paper/chunk/system/RegionizedPlayerChunkLoader.java +index 1b090f1e79b996e52097afc49c1cec85936653e6..7355978db3b7cfbc7503d7c2738868fcf10f6bf2 100644 +--- a/src/main/java/io/papermc/paper/chunk/system/RegionizedPlayerChunkLoader.java ++++ b/src/main/java/io/papermc/paper/chunk/system/RegionizedPlayerChunkLoader.java +@@ -1107,6 +1107,16 @@ public class RegionizedPlayerChunkLoader { + + // now all tickets should be removed, which is all of our external state + } ++ ++ // For external checks ++ public boolean isChunkSent(long chunkKey) { ++ return this.sentChunks.contains(chunkKey); ++ } ++ ++ // For external checks ++ public it.unimi.dsi.fastutil.longs.LongSet getSentChunks() { ++ return it.unimi.dsi.fastutil.longs.LongSets.unmodifiable(this.sentChunks); ++ } + } + + // TODO rebase into util patch +diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +index e77bf7f432387bdfa7f69d31b014e8cd254fd4ca..693c07f427ee4f1b3056c741bb0aba7c08201a55 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +@@ -3390,6 +3390,37 @@ public class CraftPlayer extends CraftHumanEntity implements Player { + } + // Paper end + ++ // Paper start - Add chunk view API ++ @Override ++ public @NotNull Set getSentChunkKeys() { ++ return this.getHandle().chunkLoader.getSentChunks(); ++ } ++ ++ @Override ++ public @NotNull Set getSentChunks() { ++ it.unimi.dsi.fastutil.longs.LongSet chunkKeys = this.getHandle().chunkLoader.getSentChunks(); ++ Set chunks = new HashSet<>(2 * chunkKeys.size()); ++ ++ it.unimi.dsi.fastutil.longs.LongIterator iterator = chunkKeys.iterator(); ++ while (iterator.hasNext()) { ++ long chunkKey = iterator.nextLong(); ++ chunks.add(this.getWorld().getChunkAt(chunkKey, false)); ++ } ++ ++ return java.util.Collections.unmodifiableSet(chunks); ++ } ++ ++ @Override ++ public boolean isChunkSent(@NotNull org.bukkit.Chunk chunk) { ++ return this.isChunkKeySent(chunk.getChunkKey()); ++ } ++ ++ @Override ++ public boolean isChunkKeySent(long chunkKey) { ++ return this.getHandle().chunkLoader.isChunkSent(chunkKey); ++ } ++ // Paper end ++ + public Player.Spigot spigot() + { + return this.spigot;