Migrate to 1.1 event system (breaks 1.0 compatibility)

This commit is contained in:
Mike Primm 2012-02-11 23:02:23 -06:00
parent 9be7c4d7ef
commit 1ef9bdd861
3 changed files with 82 additions and 549 deletions

View File

@ -1,449 +0,0 @@
package org.dynmap.bukkit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.bukkit.event.CustomEventListener;
import org.bukkit.event.Event;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkPopulateEvent;
import org.bukkit.event.world.SpawnChangeEvent;
import org.bukkit.event.world.WorldListener;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.dynmap.Log;
public class BukkitEventProcessor {
private Plugin plugin;
private PluginManager pm;
private HashMap<Event.Type, List<Listener>> event_handlers = new HashMap<Event.Type, List<Listener>>();
public BukkitEventProcessor(Plugin plugin) {
this.plugin = plugin;
this.pm = plugin.getServer().getPluginManager();
}
public void cleanup() {
/* Clean up all registered handlers */
for(Event.Type t : event_handlers.keySet()) {
List<Listener> ll = event_handlers.get(t);
ll.clear(); /* Empty list - we use presence of list to remember that we've registered with Bukkit */
}
if(plugin.getServer().getVersion().contains("(MC: 1.0") == false) {
event_handlers.clear();
}
}
private BlockListener ourBlockEventHandler = new BlockListener() {
@Override
public void onBlockPlace(BlockPlaceEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockPlace(event);
}
}
}
@Override
public void onBlockBreak(BlockBreakEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockBreak(event);
}
}
}
@Override
public void onLeavesDecay(LeavesDecayEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onLeavesDecay(event);
}
}
}
@Override
public void onBlockBurn(BlockBurnEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockBurn(event);
}
}
}
@Override
public void onBlockForm(BlockFormEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockForm(event);
}
}
}
@Override
public void onBlockFade(BlockFadeEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockFade(event);
}
}
}
@Override
public void onBlockSpread(BlockSpreadEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockSpread(event);
}
}
}
@Override
public void onBlockFromTo(BlockFromToEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockFromTo(event);
}
}
}
@Override
public void onBlockPhysics(BlockPhysicsEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockPhysics(event);
}
}
}
@Override
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockPistonRetract(event);
}
}
}
@Override
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockPistonExtend(event);
}
}
}
@Override
public void onSignChange(SignChangeEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onSignChange(event);
}
}
}
};
private PlayerListener ourPlayerEventHandler = new PlayerListener() {
@Override
public void onPlayerJoin(PlayerJoinEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((PlayerListener)l).onPlayerJoin(event);
}
}
}
@Override
public void onPlayerLogin(PlayerLoginEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((PlayerListener)l).onPlayerLogin(event);
}
}
}
@Override
public void onPlayerMove(PlayerMoveEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((PlayerListener)l).onPlayerMove(event);
}
}
}
@Override
public void onPlayerQuit(PlayerQuitEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((PlayerListener)l).onPlayerQuit(event);
}
}
}
@Override
public void onPlayerBedLeave(PlayerBedLeaveEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((PlayerListener)l).onPlayerBedLeave(event);
}
}
}
@Override
public void onPlayerChat(PlayerChatEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((PlayerListener)l).onPlayerChat(event);
}
}
}
};
private WorldListener ourWorldEventHandler = new WorldListener() {
@Override
public void onWorldLoad(WorldLoadEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((WorldListener)l).onWorldLoad(event);
}
}
}
@Override
public void onWorldUnload(WorldUnloadEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((WorldListener)l).onWorldUnload(event);
}
}
}
@Override
public void onChunkLoad(ChunkLoadEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((WorldListener)l).onChunkLoad(event);
}
}
}
@Override
public void onChunkPopulate(ChunkPopulateEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((WorldListener)l).onChunkPopulate(event);
}
}
}
@Override
public void onSpawnChange(SpawnChangeEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((WorldListener)l).onSpawnChange(event);
}
}
}
};
private CustomEventListener ourCustomEventHandler = new CustomEventListener() {
@Override
public void onCustomEvent(Event event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((CustomEventListener)l).onCustomEvent(event);
}
}
}
};
private EntityListener ourEntityEventHandler = new EntityListener() {
@Override
public void onEntityExplode(EntityExplodeEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((EntityListener)l).onEntityExplode(event);
}
}
}
};
private ServerListener ourServerEventHandler = new ServerListener() {
@Override
public void onPluginEnable(PluginEnableEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((ServerListener)l).onPluginEnable(event);
}
}
}
@Override
public void onPluginDisable(PluginDisableEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((ServerListener)l).onPluginDisable(event);
}
}
}
};
/**
* Register event listener - this will be cleaned up properly on a /dynmap reload, unlike
* registering with Bukkit directly
*/
public void registerEvent(Event.Type type, Listener listener) {
List<Listener> ll = event_handlers.get(type);
if(ll == null) {
switch(type) { /* See if it is a type we're brokering */
case PLAYER_LOGIN:
case PLAYER_CHAT:
case PLAYER_JOIN:
case PLAYER_QUIT:
case PLAYER_MOVE:
case PLAYER_BED_LEAVE:
pm.registerEvent(type, ourPlayerEventHandler, Event.Priority.Monitor, plugin);
break;
case BLOCK_PLACE:
case BLOCK_BREAK:
case LEAVES_DECAY:
case BLOCK_BURN:
case BLOCK_FORM:
case BLOCK_FADE:
case BLOCK_SPREAD:
case BLOCK_FROMTO:
case BLOCK_PHYSICS:
case BLOCK_PISTON_EXTEND:
case BLOCK_PISTON_RETRACT:
pm.registerEvent(type, ourBlockEventHandler, Event.Priority.Monitor, plugin);
break;
case SIGN_CHANGE:
pm.registerEvent(type, ourBlockEventHandler, Event.Priority.Low, plugin);
break;
case WORLD_LOAD:
case WORLD_UNLOAD:
case CHUNK_LOAD:
case CHUNK_POPULATED:
case SPAWN_CHANGE:
pm.registerEvent(type, ourWorldEventHandler, Event.Priority.Monitor, plugin);
break;
case CUSTOM_EVENT:
pm.registerEvent(type, ourCustomEventHandler, Event.Priority.Monitor, plugin);
break;
case ENTITY_EXPLODE:
pm.registerEvent(type, ourEntityEventHandler, Event.Priority.Monitor, plugin);
break;
case PLUGIN_ENABLE:
case PLUGIN_DISABLE:
pm.registerEvent(type, ourServerEventHandler, Event.Priority.Monitor, plugin);
break;
default:
Log.severe("registerEvent() in DynmapPlugin does not handle " + type);
return;
}
ll = new ArrayList<Listener>();
event_handlers.put(type, ll); /* Add list for this event */
}
ll.add(listener);
}
}

View File

@ -18,14 +18,14 @@ import org.bukkit.block.BlockFace;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Type;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
@ -34,16 +34,13 @@ import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.world.ChunkPopulateEvent;
import org.bukkit.event.world.SpawnChangeEvent;
import org.bukkit.event.world.WorldListener;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.plugin.Plugin;
@ -73,13 +70,13 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
private DynmapCore core;
private PermissionProvider permissions;
private String version;
public BukkitEventProcessor bep;
public SnapshotCache sscache;
private boolean has_spout = false;
public PlayerList playerList;
private MapManager mapManager;
public static DynmapPlugin plugin;
public SpoutPluginBlocks spb;
public PluginManager pm;
public DynmapPlugin() {
plugin = this;
@ -149,52 +146,53 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
/* Already called for normal world activation/deactivation */
break;
case WORLD_SPAWN_CHANGE:
bep.registerEvent(Type.SPAWN_CHANGE, new WorldListener() {
@Override
pm.registerEvents(new Listener() {
@EventHandler(priority=EventPriority.MONITOR)
public void onSpawnChange(SpawnChangeEvent evt) {
DynmapWorld w = new BukkitWorld(evt.getWorld());
core.listenerManager.processWorldEvent(EventType.WORLD_SPAWN_CHANGE, w);
}
});
}, DynmapPlugin.this);
break;
case PLAYER_JOIN:
case PLAYER_QUIT:
/* Already handled */
break;
case PLAYER_BED_LEAVE:
bep.registerEvent(Type.PLAYER_BED_LEAVE, new PlayerListener() {
@Override
pm.registerEvents(new Listener() {
@EventHandler(priority=EventPriority.MONITOR)
public void onPlayerBedLeave(PlayerBedLeaveEvent evt) {
DynmapPlayer p = new BukkitPlayer(evt.getPlayer());
core.listenerManager.processPlayerEvent(EventType.PLAYER_BED_LEAVE, p);
}
});
}, DynmapPlugin.this);
break;
case PLAYER_CHAT:
bep.registerEvent(Type.PLAYER_CHAT, new PlayerListener() {
@Override
pm.registerEvents(new Listener() {
@EventHandler(priority=EventPriority.MONITOR)
public void onPlayerChat(PlayerChatEvent evt) {
if(evt.isCancelled()) return;
DynmapPlayer p = null;
if(evt.getPlayer() != null)
p = new BukkitPlayer(evt.getPlayer());
core.listenerManager.processChatEvent(EventType.PLAYER_CHAT, p, evt.getMessage());
}
});
}, DynmapPlugin.this);
break;
case BLOCK_BREAK:
bep.registerEvent(Type.BLOCK_BREAK, new BlockListener() {
@Override
pm.registerEvents(new Listener() {
@EventHandler(priority=EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent evt) {
Block b = evt.getBlock();
Location l = b.getLocation();
core.listenerManager.processBlockEvent(EventType.BLOCK_BREAK, b.getType().getId(),
l.getWorld().getName(), l.getBlockX(), l.getBlockY(), l.getBlockZ());
}
});
}, DynmapPlugin.this);
break;
case SIGN_CHANGE:
bep.registerEvent(Type.SIGN_CHANGE, new BlockListener() {
@Override
pm.registerEvents(new Listener() {
@EventHandler(priority=EventPriority.MONITOR)
public void onSignChange(SignChangeEvent evt) {
Block b = evt.getBlock();
Location l = b.getLocation();
@ -205,7 +203,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
core.listenerManager.processSignChangeEvent(EventType.SIGN_CHANGE, b.getType().getId(),
l.getWorld().getName(), l.getBlockX(), l.getBlockY(), l.getBlockZ(), lines, dp);
}
});
}, DynmapPlugin.this);
break;
default:
Log.severe("Unhandled event type: " + type);
@ -341,12 +339,11 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
@Override
public void onEnable() {
pm = this.getServer().getPluginManager();
PluginDescriptionFile pdfFile = this.getDescription();
version = pdfFile.getVersion();
/* Initialize event processor */
if(bep == null)
bep = new BukkitEventProcessor(this);
/* Set up player login/quit event handler */
registerPlayerLoginListener();
@ -413,8 +410,6 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
@Override
public void onDisable() {
/* Reset registered listeners */
bep.cleanup();
/* Disable core */
core.disableCore();
@ -550,18 +545,19 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
}
private void registerPlayerLoginListener() {
PlayerListener pl = new PlayerListener() {
Listener pl = new Listener() {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent evt) {
DynmapPlayer dp = new BukkitPlayer(evt.getPlayer());
core.listenerManager.processPlayerEvent(EventType.PLAYER_JOIN, dp);
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent evt) {
DynmapPlayer dp = new BukkitPlayer(evt.getPlayer());
core.listenerManager.processPlayerEvent(EventType.PLAYER_QUIT, dp);
}
};
bep.registerEvent(Type.PLAYER_JOIN, pl);
bep.registerEvent(Type.PLAYER_QUIT, pl);
pm.registerEvents(pl, this);
}
private boolean onplace;
@ -580,8 +576,8 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
private boolean onexplosion;
private void registerEvents() {
BlockListener blockTrigger = new BlockListener() {
@Override
Listener blockTrigger = new Listener() {
@EventHandler(priority=EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event) {
if(event.isCancelled())
return;
@ -593,7 +589,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
}
}
@Override
@EventHandler(priority=EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent event) {
if(event.isCancelled())
return;
@ -605,7 +601,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
}
}
@Override
@EventHandler(priority=EventPriority.MONITOR)
public void onLeavesDecay(LeavesDecayEvent event) {
if(event.isCancelled())
return;
@ -617,7 +613,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
}
}
@Override
@EventHandler(priority=EventPriority.MONITOR)
public void onBlockBurn(BlockBurnEvent event) {
if(event.isCancelled())
return;
@ -629,7 +625,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
}
}
@Override
@EventHandler(priority=EventPriority.MONITOR)
public void onBlockForm(BlockFormEvent event) {
if(event.isCancelled())
return;
@ -641,7 +637,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
}
}
@Override
@EventHandler(priority=EventPriority.MONITOR)
public void onBlockFade(BlockFadeEvent event) {
if(event.isCancelled())
return;
@ -653,7 +649,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
}
}
@Override
@EventHandler(priority=EventPriority.MONITOR)
public void onBlockSpread(BlockSpreadEvent event) {
if(event.isCancelled())
return;
@ -665,7 +661,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
}
}
@Override
@EventHandler(priority=EventPriority.MONITOR)
public void onBlockFromTo(BlockFromToEvent event) {
if(event.isCancelled())
return;
@ -681,7 +677,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockfromto");
}
@Override
@EventHandler(priority=EventPriority.MONITOR)
public void onBlockPhysics(BlockPhysicsEvent event) {
if(event.isCancelled())
return;
@ -693,7 +689,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
}
}
@Override
@EventHandler(priority=EventPriority.MONITOR)
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
if(event.isCancelled())
return;
@ -719,7 +715,8 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
mapManager.touch(wn, x, y, z, "pistonretract");
}
}
@Override
@EventHandler(priority=EventPriority.MONITOR)
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
if(event.isCancelled())
return;
@ -749,40 +746,22 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
// To trigger rendering.
onplace = core.isTrigger("blockplaced");
bep.registerEvent(Event.Type.BLOCK_PLACE, blockTrigger);
onbreak = core.isTrigger("blockbreak");
bep.registerEvent(Event.Type.BLOCK_BREAK, blockTrigger);
if(core.isTrigger("snowform")) Log.info("The 'snowform' trigger has been deprecated due to Bukkit changes - use 'blockformed'");
onleaves = core.isTrigger("leavesdecay");
bep.registerEvent(Event.Type.LEAVES_DECAY, blockTrigger);
onburn = core.isTrigger("blockburn");
bep.registerEvent(Event.Type.BLOCK_BURN, blockTrigger);
onblockform = core.isTrigger("blockformed");
bep.registerEvent(Event.Type.BLOCK_FORM, blockTrigger);
onblockfade = core.isTrigger("blockfaded");
bep.registerEvent(Event.Type.BLOCK_FADE, blockTrigger);
onblockspread = core.isTrigger("blockspread");
bep.registerEvent(Event.Type.BLOCK_SPREAD, blockTrigger);
onblockfromto = core.isTrigger("blockfromto");
bep.registerEvent(Event.Type.BLOCK_FROMTO, blockTrigger);
onblockphysics = core.isTrigger("blockphysics");
bep.registerEvent(Event.Type.BLOCK_PHYSICS, blockTrigger);
onpiston = core.isTrigger("pistonmoved");
bep.registerEvent(Event.Type.BLOCK_PISTON_EXTEND, blockTrigger);
bep.registerEvent(Event.Type.BLOCK_PISTON_RETRACT, blockTrigger);
pm.registerEvents(blockTrigger, this);
/* Register player event trigger handlers */
PlayerListener playerTrigger = new PlayerListener() {
@Override
Listener playerTrigger = new Listener() {
@EventHandler(priority=EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
if(onplayerjoin) {
Location loc = event.getPlayer().getLocation();
@ -790,29 +769,30 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
}
core.listenerManager.processPlayerEvent(EventType.PLAYER_JOIN, new BukkitPlayer(event.getPlayer()));
}
@Override
@EventHandler(priority=EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
core.listenerManager.processPlayerEvent(EventType.PLAYER_QUIT, new BukkitPlayer(event.getPlayer()));
}
@Override
public void onPlayerMove(PlayerMoveEvent event) {
Location loc = event.getPlayer().getLocation();
mapManager.touch(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "playermove");
}
};
onplayerjoin = core.isTrigger("playerjoin");
onplayermove = core.isTrigger("playermove");
bep.registerEvent(Event.Type.PLAYER_JOIN, playerTrigger);
bep.registerEvent(Event.Type.PLAYER_QUIT, playerTrigger);
pm.registerEvents(playerTrigger, this);
if(onplayermove) {
bep.registerEvent(Event.Type.PLAYER_MOVE, playerTrigger);
Listener playermove = new Listener() {
@EventHandler(priority=EventPriority.MONITOR)
public void onPlayerMove(PlayerMoveEvent event) {
Location loc = event.getPlayer().getLocation();
mapManager.touch(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "playermove");
}
};
pm.registerEvents(playermove, this);
Log.warning("playermove trigger enabled - this trigger can cause excessive tile updating: use with caution");
}
/* Register entity event triggers */
EntityListener entityTrigger = new EntityListener() {
@Override
Listener entityTrigger = new Listener() {
@EventHandler(priority=EventPriority.MONITOR)
public void onEntityExplode(EntityExplodeEvent event) {
Location loc = event.getLocation();
String wname = loc.getWorld().getName();
@ -841,27 +821,18 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
}
};
onexplosion = core.isTrigger("explosion");
bep.registerEvent(Event.Type.ENTITY_EXPLODE, entityTrigger);
pm.registerEvents(entityTrigger, this);
/* Register world event triggers */
WorldListener worldTrigger = new WorldListener() {
@Override
public void onChunkPopulate(ChunkPopulateEvent event) {
Chunk c = event.getChunk();
/* Touch extreme corners */
int x = c.getX() << 4;
int z = c.getZ() << 4;
mapManager.touchVolume(event.getWorld().getName(), x, 0, z, x+15, 128, z+16, "chunkpopulate");
}
@Override
Listener worldTrigger = new Listener() {
@EventHandler(priority=EventPriority.MONITOR)
public void onWorldLoad(WorldLoadEvent event) {
core.updateConfigHashcode();
BukkitWorld w = new BukkitWorld(event.getWorld());
if(core.processWorldLoad(w)) /* Have core process load first - fire event listeners if good load after */
core.listenerManager.processWorldEvent(EventType.WORLD_LOAD, w);
}
@Override
@EventHandler(priority=EventPriority.MONITOR)
public void onWorldUnload(WorldUnloadEvent event) {
core.updateConfigHashcode();
DynmapWorld w = core.getWorld(event.getWorld().getName());
@ -869,15 +840,23 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
core.listenerManager.processWorldEvent(EventType.WORLD_UNLOAD, w);
}
};
// To link configuration to real loaded worlds.
pm.registerEvents(worldTrigger, this);
ongeneratechunk = core.isTrigger("chunkgenerated");
if(ongeneratechunk) {
bep.registerEvent(Event.Type.CHUNK_POPULATED, worldTrigger);
Listener chunkTrigger = new Listener() {
@EventHandler(priority=EventPriority.MONITOR)
public void onChunkPopulate(ChunkPopulateEvent event) {
Chunk c = event.getChunk();
/* Touch extreme corners */
int x = c.getX() << 4;
int z = c.getZ() << 4;
mapManager.touchVolume(event.getWorld().getName(), x, 0, z, x+15, 128, z+16, "chunkpopulate");
}
};
pm.registerEvents(chunkTrigger, this);
}
// To link configuration to real loaded worlds.
bep.registerEvent(Event.Type.WORLD_LOAD, worldTrigger);
bep.registerEvent(Event.Type.WORLD_UNLOAD, worldTrigger);
}
private boolean detectSpout() {

View File

@ -6,6 +6,8 @@ import java.util.List;
import org.bukkit.event.CustomEventListener;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;
@ -28,8 +30,8 @@ public class HeroChatHandler {
private DynmapCore core;
private HeroChatChannel hcwebinputchan;
private class OurPluginListener extends ServerListener {
@Override
private class OurPluginListener implements Listener {
@EventHandler
public void onPluginEnable(PluginEnableEvent event) {
Plugin plugin = event.getPlugin();
String name = plugin.getDescription().getName();
@ -209,7 +211,7 @@ public class HeroChatHandler {
/**
* Handle custom events
*/
@Override
@EventHandler
public void onCustomEvent(Event event) {
if (HeroChatChannelEvent.isInstance(event)) {
HeroChatChannelEvent ce = new HeroChatChannelEvent(event);
@ -261,7 +263,7 @@ public class HeroChatHandler {
}
else {
/* Set up to hear when HeroChat is enabled */
DynmapPlugin.plugin.bep.registerEvent(Event.Type.PLUGIN_ENABLE, new OurPluginListener());
DynmapPlugin.plugin.pm.registerEvents(new OurPluginListener(), DynmapPlugin.plugin);
}
}
@ -279,7 +281,8 @@ public class HeroChatHandler {
return;
}
/* Register event handler */
DynmapPlugin.plugin.bep.registerEvent(Event.Type.CUSTOM_EVENT, new OurEventListener());
DynmapPlugin.plugin.pm.registerEvent(Event.Type.CUSTOM_EVENT, new OurEventListener(), Event.Priority.Monitor, DynmapPlugin.plugin);
Log.verboseinfo("HeroChat integration active");
}
/**