Added a few null pointer checks and performed minor touchups (tried improving a few equals, clone and hashCode methods).

By: VictorD <victor.danell@gmail.com>
This commit is contained in:
Bukkit/Spigot
2011-03-05 12:27:51 +01:00
parent 5673661da0
commit bb755bb9a2
9 changed files with 51 additions and 16 deletions

View File

@@ -7,10 +7,8 @@ import org.bukkit.block.BlockFace;
import org.bukkit.entity.LivingEntity;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.lang.IllegalStateException;
import java.lang.Exception;
/**
* This class performs ray tracing and iterates along blocks on a line
@@ -23,7 +21,7 @@ public class BlockIterator implements Iterator<Block> {
private final World world;
private final int maxDistance;
private final int gridSize = 1<<24;
private static final int gridSize = 1<<24;
private boolean end = false;

View File

@@ -102,6 +102,10 @@ public class BlockVector extends Vector {
*/
@Override
public BlockVector clone() {
return new BlockVector(x, y, z);
BlockVector v = (BlockVector)super.clone();
v.x = x;
v.y = y;
v.z = z;
return v;
}
}

View File

@@ -522,7 +522,7 @@ public class Vector implements Cloneable {
return Math.abs(x - other.x) < epsilon
&& Math.abs(y - other.y) < epsilon
&& Math.abs(z - other.z) < epsilon;
&& Math.abs(z - other.z) < epsilon && (this.getClass().equals(obj.getClass()));
}
/**
@@ -546,7 +546,16 @@ public class Vector implements Cloneable {
*/
@Override
public Vector clone() {
return new Vector(x, y, z);
try {
Vector v = (Vector)super.clone();
v.x = x;
v.y = y;
v.z = z;
return v;
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return null;
}
/**