aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFlorian Beck <[email protected]>2024-04-20 19:56:59 +0200
committerGitHub <[email protected]>2024-04-20 13:56:59 -0400
commita033033b7a021f5ba3b3bf815a59a55cc3d7deab (patch)
treed160065238f6af355f2c02fae2cf9fe5e420d3bc
parent3af134652070c43fa70568203ccdd974d1503533 (diff)
downloadPaper-a033033b7a021f5ba3b3bf815a59a55cc3d7deab.tar.gz
Paper-a033033b7a021f5ba3b3bf815a59a55cc3d7deab.zip
Added chunk view API (#10398)
-rw-r--r--patches/api/0471-API-for-checking-sent-chunks.patch58
-rw-r--r--patches/server/1057-API-for-checking-sent-chunks.patch62
2 files changed, 120 insertions, 0 deletions
diff --git a/patches/api/0471-API-for-checking-sent-chunks.patch b/patches/api/0471-API-for-checking-sent-chunks.patch
new file mode 100644
index 0000000000..30170f4dfe
--- /dev/null
+++ b/patches/api/0471-API-for-checking-sent-chunks.patch
@@ -0,0 +1,58 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Flo0 <[email protected]>
+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..d048ae07cc33fd77d128cc1ebf88b0804969fa3c 100644
+--- a/src/main/java/org/bukkit/entity/Player.java
++++ b/src/main/java/org/bukkit/entity/Player.java
+@@ -3707,6 +3707,47 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
+ void resetIdleDuration();
+ // Paper end
+
++ // Paper start - Add chunk view API
++ /**
++ * Gets the a set of chunk keys for all chunks that have been sent to the player.
++ *
++ * @return an immutable set of chunk keys
++ * @apiNote currently marked as experimental to gather feedback regarding the returned set being an immutable copy
++ * vs it potentially being an unmodifiable view of the set chunks.
++ */
++ @ApiStatus.Experimental
++ java.util.@NotNull @org.jetbrains.annotations.Unmodifiable Set<Long> getSentChunkKeys();
++
++ /**
++ * Gets the set of chunks that have been sent to the player.
++ *
++ * @return an immutable set of chunks
++ * @apiNote currently marked as experimental to gather feedback regarding the returned set being an immutable copy
++ * vs it potentially being an unmodifiable view of the set chunks.
++ */
++ @ApiStatus.Experimental
++ java.util.@NotNull @org.jetbrains.annotations.Unmodifiable Set<org.bukkit.Chunk> 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
++ */
++ default boolean isChunkSent(@NotNull org.bukkit.Chunk chunk) {
++ return this.isChunkSent(chunk.getChunkKey());
++ }
++
++ /**
++ * Checks if the player has been sent a specific chunk.
++ *
++ * @param chunkKey the chunk key to check
++ * @return true if the player has been sent the chunk, false otherwise
++ * @see org.bukkit.Chunk#getChunkKey()
++ */
++ boolean isChunkSent(long chunkKey);
++ // Paper end
++
+ @NotNull
+ @Override
+ Spigot spigot();
diff --git a/patches/server/1057-API-for-checking-sent-chunks.patch b/patches/server/1057-API-for-checking-sent-chunks.patch
new file mode 100644
index 0000000000..4e4a9e5e87
--- /dev/null
+++ b/patches/server/1057-API-for-checking-sent-chunks.patch
@@ -0,0 +1,62 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Flo0 <[email protected]>
+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..bf3c5efa0d58c58a5b0b6b73880aaf03c8a37c12 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,11 @@ public class RegionizedPlayerChunkLoader {
+
+ // now all tickets should be removed, which is all of our external state
+ }
++
++ // For external checks
++ public it.unimi.dsi.fastutil.longs.LongOpenHashSet getSentChunksRaw() {
++ return 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 4aa6084fb3540f7811f13e09b5d11e2e0cf48220..d5dd3c0d50ad34fe339f7aaaba0652ec69441e44 100644
+--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+@@ -3390,6 +3390,35 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
+ }
+ // Paper end
+
++ // Paper start - Add chunk view API
++ @Override
++ public Set<java.lang.Long> getSentChunkKeys() {
++ org.spigotmc.AsyncCatcher.catchOp("accessing sent chunks");
++ return it.unimi.dsi.fastutil.longs.LongSets.unmodifiable(
++ this.getHandle().chunkLoader.getSentChunksRaw().clone()
++ );
++ }
++
++ @Override
++ public Set<org.bukkit.Chunk> getSentChunks() {
++ org.spigotmc.AsyncCatcher.catchOp("accessing sent chunks");
++ final it.unimi.dsi.fastutil.longs.LongOpenHashSet rawChunkKeys = this.getHandle().chunkLoader.getSentChunksRaw();
++ final it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<org.bukkit.Chunk> chunks = new it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<>(rawChunkKeys.size());
++ final org.bukkit.World world = this.getWorld();
++
++ final it.unimi.dsi.fastutil.longs.LongIterator iter = this.getHandle().chunkLoader.getSentChunksRaw().longIterator();
++ while (iter.hasNext()) chunks.add(world.getChunkAt(iter.nextLong(), false));
++
++ return it.unimi.dsi.fastutil.objects.ObjectSets.unmodifiable(chunks);
++ }
++
++ @Override
++ public boolean isChunkSent(final long chunkKey) {
++ org.spigotmc.AsyncCatcher.catchOp("accessing sent chunks");
++ return this.getHandle().chunkLoader.getSentChunksRaw().contains(chunkKey);
++ }
++ // Paper end
++
+ public Player.Spigot spigot()
+ {
+ return this.spigot;