13
0
geforkt von Mirrors/Paper

Improved some debug in Location.

By: Tahg <tahgtahv@gmail.com>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2012-01-09 23:44:46 -05:00
Ursprung 387d09faa1
Commit 21e1a5b725

Datei anzeigen

@ -360,7 +360,11 @@ public class Location implements Cloneable {
* @throws IllegalArgumentException for differing worlds * @throws IllegalArgumentException for differing worlds
*/ */
public double distance(Location o) { public double distance(Location o) {
return Math.sqrt(distanceSquared(o)); if (o == null || o.getWorld() != getWorld()) {
throw new IllegalArgumentException("Cannot measure distance between worlds or to null");
}
return Math.sqrt(Math.pow(x - o.x, 2) + Math.pow(y - o.y, 2) + Math.pow(z - o.z, 2));
} }
/** /**
@ -372,10 +376,8 @@ public class Location implements Cloneable {
* @throws IllegalArgumentException for differing worlds * @throws IllegalArgumentException for differing worlds
*/ */
public double distanceSquared(Location o) { public double distanceSquared(Location o) {
if (o == null) { if (o == null || o.getWorld() != getWorld()) {
throw new IllegalArgumentException("Cannot measure distance to a null world"); throw new IllegalArgumentException("Cannot measure distance between worlds or to null");
} else if (o == null || o.getWorld() != getWorld()) {
throw new IllegalArgumentException("Cannot measure distance between " + getWorld().getName() + " and " + o.getWorld().getName());
} }
return Math.pow(x - o.x, 2) + Math.pow(y - o.y, 2) + Math.pow(z - o.z, 2); return Math.pow(x - o.x, 2) + Math.pow(y - o.y, 2) + Math.pow(z - o.z, 2);