Files
OldSliceMC/patches/api/0011-Add-PlayerPreChunkLoadEvent.patch
2024-02-13 21:54:38 -06:00

98 lines
2.8 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Cryptite <cryptite@gmail.com>
Date: Mon, 10 Apr 2023 08:47:44 -0500
Subject: [PATCH] Add 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..946af80dd54f602b5ceb61365ca98b06411f8177
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/packet/PlayerPreChunkLoadEvent.java
@@ -0,0 +1,70 @@
+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}
+ * <p>
+ * 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(@NotNull 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;
+ }
+
+ @NotNull
+ 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 671321b77475f20ec1cf682a184d42497160dce3..2b9547dd059cb1e6dd224de813ba2193e2440135 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -527,6 +527,9 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
//@Deprecated // Paper
public boolean refreshChunk(int x, int z);
+ @NotNull
+ it.unimi.dsi.fastutil.longs.LongOpenHashSet getSentChunks(@NotNull Player p); // Slice
+
/**
* Gets whether the chunk at the specified chunk coordinates is force
* loaded.