From 950ed1a52ac116ca9a1b0656e9b22ae6d63a8207 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Tue, 4 Jan 2011 14:08:56 +0000 Subject: [PATCH] Added Chunk events in new World category By: Dinnerbone --- .../bukkit/event/world/ChunkLoadedEvent.java | 26 ++++++++++++++++++ .../event/world/ChunkUnloadedEvent.java | 25 +++++++++++++++++ .../org/bukkit/event/world/WorldEvent.java | 27 +++++++++++++++++++ .../org/bukkit/event/world/WorldListener.java | 25 +++++++++++++++++ .../bukkit/plugin/java/JavaPluginLoader.java | 14 ++++++++++ 5 files changed, 117 insertions(+) create mode 100644 paper-api/src/main/java/org/bukkit/event/world/ChunkLoadedEvent.java create mode 100644 paper-api/src/main/java/org/bukkit/event/world/ChunkUnloadedEvent.java create mode 100644 paper-api/src/main/java/org/bukkit/event/world/WorldEvent.java create mode 100644 paper-api/src/main/java/org/bukkit/event/world/WorldListener.java diff --git a/paper-api/src/main/java/org/bukkit/event/world/ChunkLoadedEvent.java b/paper-api/src/main/java/org/bukkit/event/world/ChunkLoadedEvent.java new file mode 100644 index 0000000000..f91b7aebe6 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/world/ChunkLoadedEvent.java @@ -0,0 +1,26 @@ + +package org.bukkit.event.world; + +import org.bukkit.Chunk; + +/** + * Called when a chunk is loaded + */ +public class ChunkLoadedEvent extends WorldEvent { + private final Chunk chunk; + + public ChunkLoadedEvent(final Type type, final Chunk chunk) { + super(type, chunk.getWorld()); + + this.chunk = chunk; + } + + /** + * Gets the chunk being loaded/unloaded + * + * @return Chunk that triggered this event + */ + public Chunk getChunk() { + return chunk; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/world/ChunkUnloadedEvent.java b/paper-api/src/main/java/org/bukkit/event/world/ChunkUnloadedEvent.java new file mode 100644 index 0000000000..3aa8922149 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/world/ChunkUnloadedEvent.java @@ -0,0 +1,25 @@ + +package org.bukkit.event.world; + +import org.bukkit.Chunk; +import org.bukkit.event.Cancellable; + +/** + * Called when a chunk is unloaded + */ +public class ChunkUnloadedEvent extends ChunkLoadedEvent implements Cancellable { + private boolean cancel = false; + + public ChunkUnloadedEvent(final Type type, final Chunk chunk) { + super(type, chunk); + } + + public boolean isCancelled() { + return cancel; + } + + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } + +} diff --git a/paper-api/src/main/java/org/bukkit/event/world/WorldEvent.java b/paper-api/src/main/java/org/bukkit/event/world/WorldEvent.java new file mode 100644 index 0000000000..d877758a99 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/world/WorldEvent.java @@ -0,0 +1,27 @@ + +package org.bukkit.event.world; + +import org.bukkit.World; +import org.bukkit.event.Event; + +/** + * Represents events within a world + */ +public class WorldEvent extends Event { + private final World world; + + public WorldEvent(final Type type, final World world) { + super(type); + + this.world = world; + } + + /** + * Gets the world primarily involved with this event + * + * @return World which caused this event + */ + public World getWorld() { + return world; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/world/WorldListener.java b/paper-api/src/main/java/org/bukkit/event/world/WorldListener.java new file mode 100644 index 0000000000..fc8f5799f3 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/world/WorldListener.java @@ -0,0 +1,25 @@ + +package org.bukkit.event.world; + +import org.bukkit.event.Listener; + +/** + * Handles all World related events + */ +public class WorldListener implements Listener { + /** + * Called when a chunk is loaded + * + * @param event Relevant event details + */ + public void onChunkLoaded(ChunkLoadedEvent event) { + } + + /** + * Called when a chunk is unloaded + * + * @param event Relevant event details + */ + public void onChunkUnloaded(ChunkUnloadedEvent event) { + } +} diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index ba220c3e64..7cbccbe8be 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -23,6 +23,9 @@ import org.bukkit.event.player.*; import org.bukkit.event.server.PluginEvent; import org.bukkit.event.server.ServerListener; import org.bukkit.event.vehicle.*; +import org.bukkit.event.world.ChunkLoadedEvent; +import org.bukkit.event.world.ChunkUnloadedEvent; +import org.bukkit.event.world.WorldListener; import org.bukkit.plugin.*; /** @@ -136,6 +139,17 @@ public final class JavaPluginLoader implements PluginLoader { trueListener.onPluginDisabled((PluginEvent)event); break; } + } else if(listener instanceof WorldListener) { + WorldListener trueListener = (WorldListener)listener; + + switch (event.getType()) { + case CHUNK_LOADED: + trueListener.onChunkLoaded((ChunkLoadedEvent)event); + break; + case CHUNK_UNLOADED: + trueListener.onChunkUnloaded((ChunkUnloadedEvent)event); + break; + } } else if(listener instanceof EntityListener) { EntityListener trueListener = (EntityListener) listener; switch(event.getType())