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/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 4fe26b5e492b5cc3ee6b99ec6ade4938acfc9ed8..2c7ec674f55b3178b9dcba7f2bc1ff5efccb50ea 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -3510,6 +3510,35 @@ public class CraftPlayer extends CraftHumanEntity implements Player { } // Paper end + // Paper start - Add chunk view API + @Override + public Set 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 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 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;