aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/1015-API-for-checking-sent-chunks.patch
blob: f3f1bf8f5c5c5a1506f0f6a24187ec87a0efb9bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
index 7249b78e21b12117480a18f2d07d0c978fe42e56..ab18bbf87dfc1455ed185a5152dad6d236565ecc 100644
--- a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
+++ b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
@@ -1078,5 +1078,10 @@ public final 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;
+        }
     }
 }
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 2f56cbcc1d1af98f58c310ff8b4ce33cc950e977..992437a6e838f653f32d33b5b3f702c484640a97 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -3484,6 +3484,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().moonrise$getChunkLoader().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().moonrise$getChunkLoader().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().moonrise$getChunkLoader().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().moonrise$getChunkLoader().getSentChunksRaw().contains(chunkKey);
+    }
+    // Paper end
+
     public Player.Spigot spigot()
     {
         return this.spigot;