From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Cryptite 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..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 415a137775f072d1aefa841b01b6bf7a5f97b6a3..ffd89e5e2039c0f1662236db112bbf25eabb0a17 100644 --- a/src/main/java/org/bukkit/World.java +++ b/src/main/java/org/bukkit/World.java @@ -525,6 +525,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.