54 lines
3.1 KiB
Diff
54 lines
3.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Cryptite <cryptite@gmail.com>
|
|
Date: Mon, 10 Apr 2023 08:47:43 -0500
|
|
Subject: [PATCH] Add PlayerPreChunkLoadEvent
|
|
|
|
|
|
diff --git a/src/main/java/io/papermc/paper/chunk/PlayerChunkLoader.java b/src/main/java/io/papermc/paper/chunk/PlayerChunkLoader.java
|
|
index e77972c4c264100ffdd824bfa2dac58dbbc6d678..5b32567bcf532994a31f184743cf42f4ea0113a4 100644
|
|
--- a/src/main/java/io/papermc/paper/chunk/PlayerChunkLoader.java
|
|
+++ b/src/main/java/io/papermc/paper/chunk/PlayerChunkLoader.java
|
|
@@ -787,7 +787,7 @@ public final class PlayerChunkLoader {
|
|
// warning: modifications of this field must be aware that the loadQueue inside PlayerChunkLoader uses this field
|
|
// in a comparator!
|
|
protected final ArrayDeque<ChunkPriorityHolder> loadQueue = new ArrayDeque<>();
|
|
- protected final LongOpenHashSet sentChunks = new LongOpenHashSet();
|
|
+ public final LongOpenHashSet sentChunks = new LongOpenHashSet(); // Slice - public
|
|
protected final LongOpenHashSet chunksToBeSent = new LongOpenHashSet();
|
|
|
|
protected final TreeSet<ChunkPriorityHolder> sendQueue = new TreeSet<>((final ChunkPriorityHolder p1, final ChunkPriorityHolder p2) -> {
|
|
@@ -871,7 +871,14 @@ public final class PlayerChunkLoader {
|
|
}
|
|
|
|
public void sendChunk(final int chunkX, final int chunkZ, final Runnable onChunkSend) {
|
|
- if (this.sentChunks.add(CoordinateUtils.getChunkKey(chunkX, chunkZ))) {
|
|
+ // Slice start
|
|
+ if (!new io.papermc.paper.event.packet.PlayerPreChunkLoadEvent(this.player.getBukkitEntity().getWorld(), chunkX, chunkZ, this.player.getBukkitEntity()).callEvent()) {
|
|
+ this.player.connection.connection.execute(onChunkSend);
|
|
+ return;
|
|
+ }
|
|
+ // Slice end
|
|
+
|
|
+ if (this.sentChunks.add(CoordinateUtils.getChunkKey(chunkX, chunkZ))) { // Slice
|
|
this.player.getLevel().getChunkSource().chunkMap.updateChunkTracking(this.player,
|
|
new ChunkPos(chunkX, chunkZ), new MutableObject<>(), false, true); // unloaded, loaded
|
|
this.player.connection.connection.execute(onChunkSend);
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
index 8334fbe6ffee640016ce17c1d331b6f88b569d65..c591b248da7f6349ce6da339f96ad9b51be042ef 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -532,6 +532,13 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
return true;
|
|
}
|
|
|
|
+ @Override
|
|
+ public it.unimi.dsi.fastutil.longs.LongOpenHashSet getSentChunks(Player p) {
|
|
+ CraftPlayer craftPlayer = (CraftPlayer) p;
|
|
+ io.papermc.paper.chunk.PlayerChunkLoader.PlayerLoaderData data = this.world.chunkSource.chunkMap.playerChunkManager.getData(craftPlayer.getHandle());
|
|
+ return data != null ? data.sentChunks : null;
|
|
+ }
|
|
+
|
|
@Override
|
|
public boolean isChunkInUse(int x, int z) {
|
|
return this.isChunkLoaded(x, z);
|