Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions patches/api/0469-API-for-checking-sent-chunks.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Flo0 <flo.roma@web.de>
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<java.lang.Long> getSentChunkKeys();
+
+ /**
+ * Gets the set of chunks that have been sent to the player.
+ *
+ * @return unmodifiable set of chunks
+ */
+ @NotNull java.util.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
+ */
+ 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();
69 changes: 69 additions & 0 deletions patches/server/1055-API-for-checking-sent-chunks.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Flo0 <flo.roma@web.de>
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<java.lang.Long> getSentChunkKeys() {
+ return this.getHandle().chunkLoader.getSentChunks();
+ }
+
+ @Override
+ public @NotNull Set<org.bukkit.Chunk> getSentChunks() {
+ it.unimi.dsi.fastutil.longs.LongSet chunkKeys = this.getHandle().chunkLoader.getSentChunks();
+ Set<org.bukkit.Chunk> 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;