package us.crast.mondochest;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;

public class BlockSearcher {
	private int radiusX;
	private int radiusY;
	private int radiusZ;
	
	public BlockSearcher(int radiusX, int radiusY, int radiusZ) {
		this.radiusX = radiusX;
		this.radiusY = radiusY;
		this.radiusZ = radiusZ;
	}
	
	public java.util.Vector<Block> findBlocks(Block contextBlock) {
		Material targetMaterial = contextBlock.getType();
		return findBlocks(contextBlock, targetMaterial, true);
	}

	public java.util.Vector<Block> findBlocks(Block contextBlock, boolean includeContext) {
		Material targetMaterial = contextBlock.getType();
		return findBlocks(contextBlock, targetMaterial, includeContext);
	}
	
	public java.util.Vector<Block> findBlocks(Block contextBlock, Material targetMaterial) {
		return findBlocks(contextBlock, targetMaterial,true);
	}
	
	public java.util.Vector<Block> findBlocks(Block contextBlock, Material targetMaterial, boolean includeContext) {
		java.util.Vector<Block> blocksFound = new java.util.Vector<Block>();
		Location loc = contextBlock.getLocation().clone();
		World world = loc.getWorld();
		// Maximum possible height can be overridden.
		int maxHeight = (MondoConfig.CONSTRAINTS_Y_MAX == -1)? (loc.getWorld().getMaxHeight() -1): MondoConfig.CONSTRAINTS_Y_MAX;
		
		int maxX = loc.getBlockX() + radiusX;
		int maxY = Math.min(loc.getBlockY() + radiusY, maxHeight);
		int maxZ = loc.getBlockZ() + radiusZ;
		
		int minY = Math.max(loc.getBlockZ() - radiusZ, MondoConfig.CONSTRAINTS_Y_MIN);
		for (int x = loc.getBlockX() - radiusX; x <= maxX; x++) {
			for (int y = minY; y <= maxY; y++) {
				for (int z = loc.getBlockZ() - radiusZ; z <= maxZ; z++) {
					Block block = world.getBlockAt(x, y, z);
					if (block.getType() == targetMaterial) {
						if (!includeContext && block.getLocation().equals(loc)) continue;
						blocksFound.add(block);
					}
				}
			}
		}
		return blocksFound;
	}
}
@@ -23,16 +23,50 @@
 chest;%0A%0A
+import java.util.logging.Logger;%0A%0A
 import o
@@ -1140,16 +1140,64 @@
 ock%3E();%0A
+%09%09//Logger log = Logger.getLogger(%22Minecraft%22);%0A
 %09%09Locati
@@ -1241,16 +1241,16 @@
 lone();%0A
-
 %09%09World 
@@ -1618,33 +1618,33 @@
 max(loc.getBlock
-Z
+Y
 () - radiusZ, Mo
@@ -1638,17 +1638,17 @@
 - radius
-Z
+Y
 , MondoC
@@ -1673,16 +1673,114 @@
 Y_MIN);%0A
+%09%09%0A%09%09//log.info(String.format(%22maxX: %25d, minY: %25d, maxY: %25d, maxZ: %25d%22, maxX, minY, maxY, maxZ));%0A
 %09%09for (i
@@ -1929,24 +1929,24 @@
 axZ; z++) %7B%0A
-
 %09%09%09%09%09Block b
@@ -1979,16 +1979,110 @@
  y, z);%0A
+%09%09%09%09%09//log.info(String.format(%22Block at %25d,%25d,%25d: %25s%22, x, y, z, block.getType().toString()));%0A
 %09%09%09%09%09if 

Fix bug which occurred in block searching at positive Z coordinates. to cause stuff to potentially not be found.