onpiston = core.isTrigger("pistonmoved");
onblockfade = core.isTrigger("blockfaded");
onblockredstone = core.isTrigger("blockredstone");
if(onplace) {
Listener placelistener = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onBlockPlace(BlockPlaceEvent event) {
Location loc = event.getBlock().getLocation();
String wn = getWorld(loc.getWorld()).getName();
sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockplace");
}
};
pm.registerEvents(placelistener, this);
}
if(onbreak) {
Listener breaklistener = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onBlockBreak(BlockBreakEvent event) {
Block b = event.getBlock();
if(b == null) return; /* Stupid mod workaround */
Location loc = b.getLocation();
String wn = getWorld(loc.getWorld()).getName();
sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockbreak");
}
};
pm.registerEvents(breaklistener, this);
}
if(onleaves) {
Listener leaveslistener = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onLeavesDecay(LeavesDecayEvent event) {
Location loc = event.getBlock().getLocation();
String wn = getWorld(loc.getWorld()).getName();
sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
if(onleaves) {
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "leavesdecay");
}
}
};
pm.registerEvents(leaveslistener, this);
}
if(onburn) {
Listener burnlistener = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onBlockBurn(BlockBurnEvent event) {
Location loc = event.getBlock().getLocation();
String wn = getWorld(loc.getWorld()).getName();
sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
if(onburn) {
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockburn");
}
}
};
pm.registerEvents(burnlistener, this);
}
if(onblockphysics) {
Listener physlistener = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onBlockPhysics(BlockPhysicsEvent event) {
Block b = event.getBlock();
Material m = b.getType();
if(m == null) return;
switch(m) {
case STATIONARY_WATER:
case WATER:
case STATIONARY_LAVA:
case LAVA:
case GRAVEL:
case SAND:
checkBlock(b, "blockphysics");
break;
default:
break;
}
}
};
pm.registerEvents(physlistener, this);
}
if(onblockfromto) {
Listener fromtolistener = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onBlockFromTo(BlockFromToEvent event) {
Block b = event.getBlock();
Material m = b.getType();
if((m != Material.WOOD_PLATE) && (m != Material.STONE_PLATE) && (m != null))
checkBlock(b, "blockfromto");
b = event.getToBlock();
m = b.getType();
if((m != Material.WOOD_PLATE) && (m != Material.STONE_PLATE) && (m != null))
checkBlock(b, "blockfromto");
}
};
pm.registerEvents(fromtolistener, this);
}
if(onpiston) {
Listener pistonlistener = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
Block b = event.getBlock();
Location loc = b.getLocation();
BlockFace dir;
try { /* Workaround Bukkit bug = http://leaky.bukkit.org/issues/1227 */
dir = event.getDirection();
} catch (ClassCastException ccx) {
dir = BlockFace.NORTH;
}
String wn = getWorld(loc.getWorld()).getName();
int x = loc.getBlockX(), y = loc.getBlockY(), z = loc.getBlockZ();
sscache.invalidateSnapshot(wn, x, y, z);
if(onpiston)
mapManager.touch(wn, x, y, z, "pistonretract");
for(int i = 0; i < 2; i++) {
x += dir.getModX();
y += dir.getModY();
z += dir.getModZ();
sscache.invalidateSnapshot(wn, x, y, z);
mapManager.touch(wn, x, y, z, "pistonretract");
}
}
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
Block b = event.getBlock();
Location loc = b.getLocation();
BlockFace dir;
try { /* Workaround Bukkit bug = http://leaky.bukkit.org/issues/1227 */
dir = event.getDirection();
} catch (ClassCastException ccx) {
dir = BlockFace.NORTH;
}
String wn = getWorld(loc.getWorld()).getName();
int x = loc.getBlockX(), y = loc.getBlockY(), z = loc.getBlockZ();
sscache.invalidateSnapshot(wn, x, y, z);
if(onpiston)
mapManager.touch(wn, x, y, z, "pistonretract");
for(int i = 0; i < 1+event.getLength(); i++) {
x += dir.getModX();
y += dir.getModY();
z += dir.getModZ();
sscache.invalidateSnapshot(wn, x, y, z);
mapManager.touch(wn, x, y, z, "pistonretract");
}
}
};
pm.registerEvents(pistonlistener, this);
}
if(onblockspread) {
Listener spreadlistener = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onBlockSpread(BlockSpreadEvent event) {
Location loc = event.getBlock().getLocation();
String wn = getWorld(loc.getWorld()).getName();
sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockspread");
}
};
pm.registerEvents(spreadlistener, this);
}
if(onblockform) {
Listener formlistener = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onBlockForm(BlockFormEvent event) {
Location loc = event.getBlock().getLocation();
String wn = getWorld(loc.getWorld()).getName();
sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockform");
}
};
pm.registerEvents(formlistener, this);
}
if(onblockfade) {
Listener fadelistener = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onBlockFade(BlockFadeEvent event) {
Location loc = event.getBlock().getLocation();
String wn = getWorld(loc.getWorld()).getName();
sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockfade");
}
};
pm.registerEvents(fadelistener, this);
}
onblockgrow = core.isTrigger("blockgrow");
if(onblockgrow) {
Listener growTrigger = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onBlockGrow(BlockGrowEvent event) {
Location loc = event.getBlock().getLocation();
String wn = getWorld(loc.getWorld()).getName();
sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockgrow");
}
};
pm.registerEvents(growTrigger, this);
}
if(onblockredstone) {
Listener redstoneTrigger = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onBlockRedstone(BlockRedstoneEvent event) {
Location loc = event.getBlock().getLocation();
String wn = getWorld(loc.getWorld()).getName();
sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockredstone");
}
};
pm.registerEvents(redstoneTrigger, this);
}
/* Register player event trigger handlers */
Listener playerTrigger = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onPlayerJoin(PlayerJoinEvent event) {
if(onplayerjoin) {
Location loc = event.getPlayer().getLocation();
mapManager.touch(getWorld(loc.getWorld()).getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "playerjoin");
}
}
};
onplayerjoin = core.isTrigger("playerjoin");
onplayermove = core.isTrigger("playermove");
pm.registerEvents(playerTrigger, this);
if(onplayermove) {
Listener playermove = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onPlayerMove(PlayerMoveEvent event) {
Location loc = event.getPlayer().getLocation();
mapManager.touch(getWorld(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 */
Listener entityTrigger = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onEntityExplode(EntityExplodeEvent event) {
Location loc = event.getLocation();
String wname = getWorld(loc.getWorld()).getName();
int minx, maxx, miny, maxy, minz, maxz;
minx = maxx = loc.getBlockX();
miny = maxy = loc.getBlockY();
minz = maxz = loc.getBlockZ();
/* Calculate volume impacted by explosion */
List<Block> blocks = event.blockList();
for(Block b: blocks) {
Location l = b.getLocation();
int x = l.getBlockX();
if(x < minx) minx = x;
if(x > maxx) maxx = x;
int y = l.getBlockY();
if(y < miny) miny = y;
if(y > maxy) maxy = y;
int z = l.getBlockZ();
if(z < minz) minz = z;
if(z > maxz) maxz = z;
}
sscache.invalidateSnapshot(wname, minx, miny, minz, maxx, maxy, maxz);
if(onexplosion) {
mapManager.touchVolume(wname, minx, miny, minz, maxx, maxy, maxz, "entityexplode");
}
}
};
onexplosion = core.isTrigger("explosion");
pm.registerEvents(entityTrigger, this);
/* Register world event triggers */
Listener worldTrigger = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onWorldLoad(WorldLoadEvent event) {
BukkitWorld w = getWorld(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);
}
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onWorldUnload(WorldUnloadEvent event) {
BukkitWorld w = getWorld(event.getWorld());
if(w != null) {
core.listenerManager.processWorldEvent(EventType.WORLD_UNLOAD, w);
w.setWorldUnloaded();
core.processWorldUnload(w);
}
}
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onStructureGrow(StructureGrowEvent event) {
Location loc = event.getLocation();
String wname = getWorld(loc.getWorld()).getName();
int minx, maxx, miny, maxy, minz, maxz;
minx = maxx = loc.getBlockX();
miny = maxy = loc.getBlockY();
minz = maxz = loc.getBlockZ();
/* Calculate volume impacted by explosion */
List<BlockState> blocks = event.getBlocks();
for(BlockState b: blocks) {
int x = b.getX();
if(x < minx) minx = x;
if(x > maxx) maxx = x;
int y = b.getY();
if(y < miny) miny = y;
if(y > maxy) maxy = y;
int z = b.getZ();
if(z < minz) minz = z;
if(z > maxz) maxz = z;
}
sscache.invalidateSnapshot(wname, minx, miny, minz, maxx, maxy, maxz);
if(onstructuregrow) {
mapManager.touchVolume(wname, minx, miny, minz, maxx, maxy, maxz, "structuregrow");
}
}
};
onstructuregrow = core.isTrigger("structuregrow");
// To link configuration to real loaded worlds.
pm.registerEvents(worldTrigger, this);
ongeneratechunk = core.isTrigger("chunkgenerated");
if(ongeneratechunk) {
Listener chunkTrigger = new Listener() {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onChunkPopulate(ChunkPopulateEvent event) {
Chunk c = event.getChunk();
ChunkSnapshot cs = c.getChunkSnapshot();
int ymax = 0;