PaperMC/patches/api/0228-Player-Chunk-Load-Unload-Events.patch

107 lines
3.2 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ysl3000 <yannicklamprecht@live.de>
Date: Mon, 5 Oct 2020 21:24:45 +0200
Subject: [PATCH] Player Chunk Load/Unload Events
diff --git a/src/main/java/io/papermc/paper/event/packet/PlayerChunkLoadEvent.java b/src/main/java/io/papermc/paper/event/packet/PlayerChunkLoadEvent.java
new file mode 100644
2024-02-01 10:15:57 +01:00
index 0000000000000000000000000000000000000000..3ddbc099a13df939b3912f30b54e7635840ba5a4
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/packet/PlayerChunkLoadEvent.java
2024-02-01 10:15:57 +01:00
@@ -0,0 +1,45 @@
2021-06-11 14:02:28 +02:00
+package io.papermc.paper.event.packet;
+
+import org.bukkit.Chunk;
+import org.bukkit.entity.Player;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.world.ChunkEvent;
2024-02-01 10:15:57 +01:00
+import org.jetbrains.annotations.ApiStatus;
2021-06-11 14:02:28 +02:00
+import org.jetbrains.annotations.NotNull;
+
+/**
2024-02-01 10:15:57 +01:00
+ * Is called when a {@link Player} receives a {@link Chunk}
2021-06-11 14:02:28 +02:00
+ * <p>
+ * Can for example be used for spawning a fake entity when the player receives a chunk.
2024-02-01 10:15:57 +01:00
+ * <p>
2021-06-11 14:02:28 +02:00
+ * Should only be used for packet/clientside related stuff.
+ * Not intended for modifying server side state.
+ */
+public class PlayerChunkLoadEvent extends ChunkEvent {
+
2024-02-01 10:15:57 +01:00
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
2021-06-11 14:02:28 +02:00
+ private final Player player;
+
2024-02-01 10:15:57 +01:00
+ @ApiStatus.Internal
2021-06-11 14:02:28 +02:00
+ public PlayerChunkLoadEvent(@NotNull Chunk chunk, @NotNull Player player) {
+ super(chunk);
+ this.player = player;
+ }
+
+ @NotNull
2024-02-01 10:15:57 +01:00
+ public Player getPlayer() {
+ return this.player;
2021-06-11 14:02:28 +02:00
+ }
+
+ @NotNull
2024-02-01 10:15:57 +01:00
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+}
diff --git a/src/main/java/io/papermc/paper/event/packet/PlayerChunkUnloadEvent.java b/src/main/java/io/papermc/paper/event/packet/PlayerChunkUnloadEvent.java
new file mode 100644
2024-02-01 10:15:57 +01:00
index 0000000000000000000000000000000000000000..2cac7e27991c04a9ced261f2dd8ad8657ccddf6b
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/packet/PlayerChunkUnloadEvent.java
2024-02-01 10:15:57 +01:00
@@ -0,0 +1,43 @@
2021-06-11 14:02:28 +02:00
+package io.papermc.paper.event.packet;
+
+import org.bukkit.Chunk;
+import org.bukkit.entity.Player;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.world.ChunkEvent;
2024-02-01 10:15:57 +01:00
+import org.jetbrains.annotations.ApiStatus;
2021-06-11 14:02:28 +02:00
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Is called when a {@link Player} receives a chunk unload packet.
2024-02-01 10:15:57 +01:00
+ * <p>
2021-06-11 14:02:28 +02:00
+ * Should only be used for packet/clientside related stuff.
+ * Not intended for modifying server side.
+ */
+public class PlayerChunkUnloadEvent extends ChunkEvent {
+
2024-02-01 10:15:57 +01:00
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
2021-06-11 14:02:28 +02:00
+ private final Player player;
+
2024-02-01 10:15:57 +01:00
+ @ApiStatus.Internal
2021-06-11 14:02:28 +02:00
+ public PlayerChunkUnloadEvent(@NotNull Chunk chunk, @NotNull Player player) {
+ super(chunk);
+ this.player = player;
+ }
+
+ @NotNull
2024-02-01 10:15:57 +01:00
+ public Player getPlayer() {
+ return this.player;
2021-06-11 14:02:28 +02:00
+ }
+
+ @NotNull
2024-02-01 10:15:57 +01:00
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+}