From e4b28b6ed7d3e1f7f32f0397abb1068483715cc0 Mon Sep 17 00:00:00 2001 From: William Blake Galbreath 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.24.0