mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 07:20:24 +01:00
Added Chunk events in new World category
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
5901415d13
commit
950ed1a52a
5 changed files with 117 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
}
|
||||
}
|
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue