for (cz = block.getZ() - radius - 1; cz <= block.getZ() + radius + 1; cz++) {
Block water = block.getWorld().getBlockAt(cx, cy, cz);
if(circularRadius && !LocationUtil.isWithinSphericalRadius(water.getLocation(), block.getLocation(), radius+1.5)) continue;
if (water.getType() == Material.WATER || water.getType() == Material.STATIONARY_WATER) {
if(BlockUtil.isBlockReplacable(water.getRelative(1, 0, 0).getType())) {
BlockFromToEvent event = new BlockFromToEvent(water, water.getRelative(1, 0, 0));
Bukkit.getPluginManager().callEvent(event);
if(!event.isCancelled())
water.getRelative(1, 0, 0).setType(Material.WATER);
}
}
}
}
// The positive x edge
cx = block.getX() + radius + 1;
for (cy = block.getY() - radius - 1; cy <= block.getY() + radius + 1; cy++) {
for (cz = block.getZ() - radius - 1; cz <= block.getZ() + radius + 1; cz++) {
Block water = block.getWorld().getBlockAt(cx, cy, cz);
if(circularRadius && !LocationUtil.isWithinSphericalRadius(water.getLocation(), block.getLocation(), radius+1.5)) continue;
if (water.getType() == Material.WATER || water.getType() == Material.STATIONARY_WATER) {
if(BlockUtil.isBlockReplacable(water.getRelative(-1, 0, 0).getType())) {
BlockFromToEvent event = new BlockFromToEvent(water, water.getRelative(-1, 0, 0));
Bukkit.getPluginManager().callEvent(event);
if(!event.isCancelled())
water.getRelative(-1, 0, 0).setType(Material.WATER);
}
}
}
}
// The negative y edge
/*cy = block.getY() - radius - 1;
for (cx = block.getX() - radius - 1; cx <= block.getX() + radius + 1; cx++) {
for (int cz = block.getZ() - radius - 1; cz <= block.getZ() + radius + 1; cz++) {
Block water = block.getWorld().getBlockAt(cx, cy, cz);
if(CraftBookPlugin.inst().getConfiguration().spongeCircleRadius && !LocationUtil.isWithinSphericalRadius(water.getLocation(), block.getLocation(), radius+1.5)) continue;
if (water.getType() == Material.WATER || water.getType() == Material.STATIONARY_WATER) {
if(BlockUtil.isBlockReplacable(water.getRelative(0, 1, 0).getType())) {
BlockFromToEvent event = new BlockFromToEvent(water, water.getRelative(0, 1, 0));
Bukkit.getPluginManager().callEvent(event);
if(!event.isCancelled())
water.getRelative(0, 1, 0).setType(Material.WATER);
}
}
}
}*/
// The positive y edge
cy = block.getY() + radius + 1;
for (cx = block.getX() - radius - 1; cx <= block.getX() + radius + 1; cx++) {
for (cz = block.getZ() - radius - 1; cz <= block.getZ() + radius + 1; cz++) {
Block water = block.getWorld().getBlockAt(cx, cy, cz);
if(circularRadius && !LocationUtil.isWithinSphericalRadius(water.getLocation(), block.getLocation(), radius+1.5)) continue;
if (water.getType() == Material.WATER || water.getType() == Material.STATIONARY_WATER) {
if(BlockUtil.isBlockReplacable(water.getRelative(0, -1, 0).getType())) {
BlockFromToEvent event = new BlockFromToEvent(water, water.getRelative(0, -1, 0));
Bukkit.getPluginManager().callEvent(event);
if(!event.isCancelled())
water.getRelative(0, -1, 0).setType(Material.WATER);
}
}
}
}
// The negative z edge
cz = block.getZ() - radius - 1;
for (cx = block.getX() - radius - 1; cx <= block.getX() + radius + 1; cx++) {
for (cy = block.getY() - radius - 1; cy <= block.getY() + radius + 1; cy++) {
Block water = block.getWorld().getBlockAt(cx, cy, cz);
if(circularRadius && !LocationUtil.isWithinSphericalRadius(water.getLocation(), block.getLocation(), radius+1.5)) continue;
if (water.getType() == Material.WATER || water.getType() == Material.STATIONARY_WATER) {
if(BlockUtil.isBlockReplacable(water.getRelative(0, 0, 1).getType())) {
BlockFromToEvent event = new BlockFromToEvent(water, water.getRelative(0, 0, 1));
Bukkit.getPluginManager().callEvent(event);
if(!event.isCancelled())
water.getRelative(0, 0, 1).setType(Material.WATER);
}
}
}
}
// The positive z edge
cz = block.getZ() + radius + 1;
for (cx = block.getX() - radius - 1; cx <= block.getX() + radius + 1; cx++) {
for (cy = block.getY() - radius - 1; cy <= block.getY() + radius + 1; cy++) {
Block water = block.getWorld().getBlockAt(cx, cy, cz);
if(circularRadius && !LocationUtil.isWithinSphericalRadius(water.getLocation(), block.getLocation(), radius+1.5)) continue;
if (water.getType() == Material.WATER || water.getType() == Material.STATIONARY_WATER) {
if(BlockUtil.isBlockReplacable(water.getRelative(0, 0, -1).getType())) {
BlockFromToEvent event = new BlockFromToEvent(water, water.getRelative(0, 0, -1));
Bukkit.getPluginManager().callEvent(event);
if(!event.isCancelled())
water.getRelative(0, 0, -1).setType(Material.WATER);
}
}
}
}