diff --git a/patches/api/0014-PlayerPreChunkLoadEvent.patch b/patches/api/0014-PlayerPreChunkLoadEvent.patch new file mode 100644 index 000000000..9fb16db20 --- /dev/null +++ b/patches/api/0014-PlayerPreChunkLoadEvent.patch @@ -0,0 +1,95 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Cryptite +Date: Fri, 18 Nov 2022 08:06:32 -0600 +Subject: [PATCH] PlayerPreChunkLoadEvent + + +diff --git a/src/main/java/io/papermc/paper/event/packet/PlayerPreChunkLoadEvent.java b/src/main/java/io/papermc/paper/event/packet/PlayerPreChunkLoadEvent.java +new file mode 100644 +index 0000000000000000000000000000000000000000..b5cc9538a70c7ce0b494d4878d51b52134c2fd75 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/event/packet/PlayerPreChunkLoadEvent.java +@@ -0,0 +1,69 @@ ++package io.papermc.paper.event.packet; ++ ++import org.bukkit.Chunk; ++import org.bukkit.World; ++import org.bukkit.entity.Player; ++import org.bukkit.event.Cancellable; ++import org.bukkit.event.Event; ++import org.bukkit.event.HandlerList; ++import org.jetbrains.annotations.NotNull; ++ ++/** ++ * Is called when a {@link Player} is about to receive a {@link Chunk} ++ *

++ * Can be cancelled, but only use if you really really mean it. ++ */ ++public class PlayerPreChunkLoadEvent extends Event implements Cancellable { ++ ++ private static final HandlerList handlers = new HandlerList(); ++ private final World world; ++ private final int chunkX; ++ private final int chunkZ; ++ private final Player player; ++ private boolean cancel; ++ ++ public PlayerPreChunkLoadEvent(World world, int chunkX, int chunkZ, @NotNull Player player) { ++ this.world = world; ++ this.chunkX = chunkX; ++ this.chunkZ = chunkZ; ++ this.player = player; ++ } ++ ++ @NotNull ++ @Override ++ public HandlerList getHandlers() { ++ return handlers; ++ } ++ ++ public World getWorld() { ++ return world; ++ } ++ ++ public int getChunkX() { ++ return chunkX; ++ } ++ ++ public int getChunkZ() { ++ return chunkZ; ++ } ++ ++ @NotNull ++ public Player getPlayer() { ++ return player; ++ } ++ ++ @Override ++ public boolean isCancelled() { ++ return cancel; ++ } ++ ++ @Override ++ public void setCancelled(boolean cancel) { ++ this.cancel = cancel; ++ } ++ ++ @NotNull ++ public static HandlerList getHandlerList() { ++ return handlers; ++ } ++} +\ No newline at end of file +diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java +index adb5fcbacf5fa284e4c6efc1dcc0f30f3932761c..27f6db119f0c720e191ba7f9b64d8aded972a8f9 100644 +--- a/src/main/java/org/bukkit/World.java ++++ b/src/main/java/org/bukkit/World.java +@@ -515,6 +515,8 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient + //@Deprecated // Paper + public boolean refreshChunk(int x, int z); + ++ it.unimi.dsi.fastutil.longs.LongOpenHashSet getSentChunks(Player p); // Slice ++ + /** + * Gets whether the chunk at the specified chunk coordinates is force + * loaded. diff --git a/patches/server/0022-PlayerPreChunkLoadEvent.patch b/patches/server/0022-PlayerPreChunkLoadEvent.patch new file mode 100644 index 000000000..87171790d --- /dev/null +++ b/patches/server/0022-PlayerPreChunkLoadEvent.patch @@ -0,0 +1,53 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Cryptite +Date: Fri, 18 Nov 2022 08:06:31 -0600 +Subject: [PATCH] PlayerPreChunkLoadEvent + + +diff --git a/src/main/java/io/papermc/paper/chunk/PlayerChunkLoader.java b/src/main/java/io/papermc/paper/chunk/PlayerChunkLoader.java +index 0b060183429f4c72ec767075538477b4302bbf0d..e4461c176682644d842b15b833c662039333d24f 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 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 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 6d92d1e1301555dd77968e9f1d7347497200dd63..24b7ea846bf19a99f670a40e3623578cfa888282 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +@@ -524,6 +524,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);