diff --git a/src/main/java/net/aufdemrand/denizen/objects/dLocation.java b/src/main/java/net/aufdemrand/denizen/objects/dLocation.java index 82532b3305..9241a7035c 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dLocation.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dLocation.java @@ -704,16 +704,17 @@ else if (yaw < 315) for (double x = -(radius); x <= radius; x++) for (double y = -(radius); y <= radius; y++) for (double z = -(radius); z <= radius; z++) - if (!materials.isEmpty()) { - for (dMaterial material : materials) { - if (material.hasData() && material.getData() != 0) { - if (material.matchesMaterialData(getBlock() - .getLocation().add(x,y,z).getBlock().getType().getNewData(getBlock() - .getLocation().add(x,y,z).getBlock().getData()))) + if (Utilities.checkLocation(this, getBlock().getLocation().add(x, y, z), radius)) + if (!materials.isEmpty()) { + for (dMaterial material : materials) { + if (material.hasData() && material.getData() != 0) { + if (material.matchesMaterialData(getBlock() + .getLocation().add(x,y,z).getBlock().getType().getNewData(getBlock() + .getLocation().add(x,y,z).getBlock().getData()))) + found.add(new dLocation(getBlock().getLocation().add(x + 0.5, y, z + 0.5))); + } + else if (material.getMaterial() == getBlock().getLocation().add(x,y,z).getBlock().getType()) found.add(new dLocation(getBlock().getLocation().add(x + 0.5, y, z + 0.5))); - } - else if (material.getMaterial() == getBlock().getLocation().add(x,y,z).getBlock().getType()) - found.add(new dLocation(getBlock().getLocation().add(x + 0.5, y, z + 0.5))); } } else found.add(new dLocation(getBlock().getLocation().add(x + 0.5, y, z + 0.5))); @@ -749,24 +750,26 @@ else if (attribute.startsWith("surface_blocks") for (double x = -(radius); x <= radius; x++) for (double y = -(radius); y <= radius; y++) for (double z = -(radius); z <= radius; z++) { - Location l = getBlock().getLocation().clone().add(x,y,z); - if (!materials.isEmpty()) { - for (dMaterial material : materials) { - if (material.matchesMaterialData(getBlock() - .getLocation().clone().add(x,y,z).getBlock().getType().getNewData(getBlock() - .getLocation().clone().add(x,y,z).getBlock().getData()))) { - if (l.clone().add(0,1,0).getBlock().getType() == Material.AIR - && l.clone().add(0,2,0).getBlock().getType() == Material.AIR - && l.getBlock().getType() != Material.AIR) - found.add(new dLocation(getBlock().getLocation().clone().add(x + 0.5, y, z + 0.5 ))); + if (Utilities.checkLocation(this, getBlock().getLocation().add(x, y, z), radius)) { + Location l = getBlock().getLocation().clone().add(x,y,z); + if (!materials.isEmpty()) { + for (dMaterial material : materials) { + if (material.matchesMaterialData(getBlock() + .getLocation().clone().add(x,y,z).getBlock().getType().getNewData(getBlock() + .getLocation().clone().add(x,y,z).getBlock().getData()))) { + if (l.clone().add(0,1,0).getBlock().getType() == Material.AIR + && l.clone().add(0,2,0).getBlock().getType() == Material.AIR + && l.getBlock().getType() != Material.AIR) + found.add(new dLocation(getBlock().getLocation().clone().add(x + 0.5, y, z + 0.5 ))); + } } } - } - else { - if (l.clone().add(0,1,0).getBlock().getType() == Material.AIR - && l.clone().add(0,2,0).getBlock().getType() == Material.AIR - && l.getBlock().getType() != Material.AIR) { - found.add(new dLocation(getBlock().getLocation().clone().add(x + 0.5, y, z + 0.5 ))); + else { + if (l.clone().add(0,1,0).getBlock().getType() == Material.AIR + && l.clone().add(0,2,0).getBlock().getType() == Material.AIR + && l.getBlock().getType() != Material.AIR) { + found.add(new dLocation(getBlock().getLocation().clone().add(x + 0.5, y, z + 0.5 ))); + } } } } diff --git a/src/main/java/net/aufdemrand/denizen/utilities/Utilities.java b/src/main/java/net/aufdemrand/denizen/utilities/Utilities.java index 36e42d758b..b309071244 100644 --- a/src/main/java/net/aufdemrand/denizen/utilities/Utilities.java +++ b/src/main/java/net/aufdemrand/denizen/utilities/Utilities.java @@ -371,8 +371,6 @@ public static boolean checkLocation(LivingEntity entity, Location theLocation, d * Checks entity's location against a Location (with leeway). Should be faster than * bukkit's built in Location.distance(Location) since there's no sqrt math. * - * Thanks chainsol :) - * * @return true if within the specified location, false otherwise. */ public static boolean checkLocation(Location baseLocation, Location theLocation, double theLeeway) { @@ -380,14 +378,7 @@ public static boolean checkLocation(Location baseLocation, Location theLocation, if (!baseLocation.getWorld().getName().equals(theLocation.getWorld().getName())) return false; - if (Math.abs(baseLocation.getX() - theLocation.getX()) - > theLeeway) return false; - if (Math.abs(baseLocation.getY() - theLocation.getY()) - > theLeeway) return false; - if (Math.abs(baseLocation.getZ() - theLocation.getZ()) - > theLeeway) return false; - - return true; + return baseLocation.distanceSquared(theLocation) < theLeeway * theLeeway; }