Files
Purpur/patches/removed/1.16/api/0013-Implement-ChunkTooLargeEvent.patch
William Blake Galbreath 2cdce3ee87 Add removed patches directory
2020-06-28 22:30:37 -05:00

129 lines
3.2 KiB
Diff

From 97b09e0112fecb7c4bd3dacf078e7cedcf402cdd Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Fri, 12 Jul 2019 02:09:58 -0500
Subject: [PATCH] Implement ChunkTooLargeEvent
---
.../pl3x/purpur/event/ChunkTooLargeEvent.java | 109 ++++++++++++++++++
1 file changed, 109 insertions(+)
create mode 100644 src/main/java/net/pl3x/purpur/event/ChunkTooLargeEvent.java
diff --git a/src/main/java/net/pl3x/purpur/event/ChunkTooLargeEvent.java b/src/main/java/net/pl3x/purpur/event/ChunkTooLargeEvent.java
new file mode 100644
index 000000000..f9d4a42c6
--- /dev/null
+++ b/src/main/java/net/pl3x/purpur/event/ChunkTooLargeEvent.java
@@ -0,0 +1,109 @@
+package net.pl3x.purpur.event;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Called when an oversized chunk loads or saves
+ */
+public class ChunkTooLargeEvent extends Event {
+ private static final HandlerList handlers = new HandlerList();
+ private final String worldName;
+ private final World world;
+ private final int chunkX;
+ private final int chunkZ;
+ private final boolean saving;
+ private final boolean overzealous;
+
+ public ChunkTooLargeEvent(@NotNull String worldName, int chunkX, int chunkZ, boolean saving, boolean overzealous) {
+ super(!Bukkit.isPrimaryThread());
+ this.worldName = worldName;
+ this.world = Bukkit.getWorld(worldName);
+ this.chunkX = chunkX;
+ this.chunkZ = chunkZ;
+ this.saving = saving;
+ this.overzealous = overzealous;
+ }
+
+ /**
+ * Get the world name according to the save directory
+ *
+ * @return World name
+ */
+ @NotNull
+ public String getWorldName() {
+ return worldName;
+ }
+
+ /**
+ * Get the world
+ *
+ * @return World, or null if world not loaded
+ */
+ @Nullable
+ public World getWorld() {
+ return world;
+ }
+
+ /**
+ * Get the X chunk coordinate
+ *
+ * @return X chunk coordinate
+ */
+ public int getChunkX() {
+ return chunkX;
+ }
+
+ /**
+ * Get the Z chunk coordinate
+ *
+ * @return Z chunk coordinate
+ */
+ public int getChunkZ() {
+ return chunkZ;
+ }
+
+ /**
+ * Whether this happened during a save attempt.
+ *
+ * @return True if saving, false if loading
+ */
+ public boolean isSaving() {
+ return saving;
+ }
+
+ /**
+ * If saving, was this is overzealous mode
+ *
+ * @return True if saving in overzealous mode
+ */
+ public boolean isOverzealous() {
+ return overzealous;
+ }
+
+ /**
+ * Get the location
+ *
+ * @return Location, or null if world not loaded
+ */
+ @Nullable
+ public Location getLocation() {
+ return world == null ? null : new Location(world, chunkX << 4, 128, chunkZ << 4);
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+}
--
2.26.2