diff options
author | VictorD <victor.danell@gmail.com> | 2011-03-05 12:27:51 +0100 |
---|---|---|
committer | VictorD <victor.danell@gmail.com> | 2011-03-05 12:27:51 +0100 |
commit | aa0614d7851eb0ffbfdaacbba4bc35d22eb37614 (patch) | |
tree | 9b54502a2be0fcacdeae0ddfa600af2b14cec2a3 /src/main | |
parent | 97d2adb53626e6e0033f303352848f1fb0b6e5f9 (diff) | |
download | bukkit-aa0614d7851eb0ffbfdaacbba4bc35d22eb37614.tar bukkit-aa0614d7851eb0ffbfdaacbba4bc35d22eb37614.tar.gz bukkit-aa0614d7851eb0ffbfdaacbba4bc35d22eb37614.tar.lz bukkit-aa0614d7851eb0ffbfdaacbba4bc35d22eb37614.tar.xz bukkit-aa0614d7851eb0ffbfdaacbba4bc35d22eb37614.zip |
Added a few null pointer checks and performed minor touchups (tried improving a few equals, clone and hashCode methods).
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/bukkit/ChatColor.java | 3 | ||||
-rw-r--r-- | src/main/java/org/bukkit/Location.java | 14 | ||||
-rw-r--r-- | src/main/java/org/bukkit/fillr/Downloader.java | 2 | ||||
-rw-r--r-- | src/main/java/org/bukkit/inventory/ItemStack.java | 18 | ||||
-rw-r--r-- | src/main/java/org/bukkit/plugin/PluginManager.java | 2 | ||||
-rw-r--r-- | src/main/java/org/bukkit/plugin/SimplePluginManager.java | 5 | ||||
-rw-r--r-- | src/main/java/org/bukkit/util/BlockIterator.java | 4 | ||||
-rw-r--r-- | src/main/java/org/bukkit/util/BlockVector.java | 6 | ||||
-rw-r--r-- | src/main/java/org/bukkit/util/Vector.java | 13 |
9 files changed, 51 insertions, 16 deletions
diff --git a/src/main/java/org/bukkit/ChatColor.java b/src/main/java/org/bukkit/ChatColor.java index bcd0da6d..2714f5f9 100644 --- a/src/main/java/org/bukkit/ChatColor.java +++ b/src/main/java/org/bukkit/ChatColor.java @@ -110,6 +110,9 @@ public enum ChatColor { * @return A copy of the input string, without any coloring */ public static String stripColor(final String input) { + if (input == null) + return null; + return input.replaceAll("(?i)\u00A7[0-F]", ""); } diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java index 250be215..583cc0bc 100644 --- a/src/main/java/org/bukkit/Location.java +++ b/src/main/java/org/bukkit/Location.java @@ -271,7 +271,19 @@ public class Location implements Cloneable { @Override public Location clone() { - return new Location(world, x, y, z, yaw, pitch); + try { + Location l = (Location)super.clone(); + l.world = world; + l.x = x; + l.y = y; + l.z = z; + l.yaw = yaw; + l.pitch = pitch; + return l; + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + return null; } /** diff --git a/src/main/java/org/bukkit/fillr/Downloader.java b/src/main/java/org/bukkit/fillr/Downloader.java index 1d324d6e..8cc76fec 100644 --- a/src/main/java/org/bukkit/fillr/Downloader.java +++ b/src/main/java/org/bukkit/fillr/Downloader.java @@ -130,7 +130,7 @@ public class Downloader { * The file to backup */ private static void backupFile(File file) { - if (file.exists()) { + if (file != null && file.exists()) { System.out.println("Backing up old file: " + file.getName()); if (!new File(BACKUP).exists()) { new File(BACKUP).mkdir(); diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java index 38ddbf75..62ed3564 100644 --- a/src/main/java/org/bukkit/inventory/ItemStack.java +++ b/src/main/java/org/bukkit/inventory/ItemStack.java @@ -182,11 +182,19 @@ public class ItemStack { }
@Override
- public boolean equals(Object object) {
- return false;
- }
-
- public boolean equals(ItemStack item) {
+ public boolean equals(Object obj) {
+ if (!(obj instanceof ItemStack))
+ return false;
+
+ ItemStack item = (ItemStack)obj;
return item.getAmount() == getAmount() && item.getTypeId() == getTypeId();
}
+
+ @Override
+ public int hashCode() {
+ int hash = 11;
+ hash = hash * 19 + 7 * getTypeId(); // Overriding hashCode since equals is overridden, it's just
+ hash = hash * 7 + 23 * getAmount(); // too bad these are mutable values... Q_Q
+ return hash;
+ }
}
diff --git a/src/main/java/org/bukkit/plugin/PluginManager.java b/src/main/java/org/bukkit/plugin/PluginManager.java index ed79abc5..e89351a0 100644 --- a/src/main/java/org/bukkit/plugin/PluginManager.java +++ b/src/main/java/org/bukkit/plugin/PluginManager.java @@ -18,7 +18,7 @@ public interface PluginManager { * @param loader Class name of the PluginLoader to register * @throws IllegalArgumentException Thrown when the given Class is not a valid PluginLoader */ - public void RegisterInterface(Class<? extends PluginLoader> loader) throws IllegalArgumentException; + public void registerInterface(Class<? extends PluginLoader> loader) throws IllegalArgumentException; /** * Checks if the given plugin is loaded and returns it when applicable diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java index 372f0845..693e2eb1 100644 --- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java +++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java @@ -53,7 +53,7 @@ public final class SimplePluginManager implements PluginManager { * @param loader Class name of the PluginLoader to register * @throws IllegalArgumentException Thrown when the given Class is not a valid PluginLoader */ - public void RegisterInterface(Class<? extends PluginLoader> loader) throws IllegalArgumentException { + public void registerInterface(Class<? extends PluginLoader> loader) throws IllegalArgumentException { PluginLoader instance; if (PluginLoader.class.isAssignableFrom(loader)) { @@ -62,7 +62,8 @@ public final class SimplePluginManager implements PluginManager { constructor = loader.getConstructor(Server.class); instance = constructor.newInstance(server); } catch (NoSuchMethodException ex) { - throw new IllegalArgumentException(String.format("Class %s does not have a public %s(Server) constructor", loader.getName()), ex); + String className = loader.getName(); + throw new IllegalArgumentException(String.format("Class %s does not have a public %s(Server) constructor", className,className), ex); } catch (Exception ex) { throw new IllegalArgumentException(String.format("Unexpected exception %s while attempting to construct a new instance of %s", ex.getClass().getName(), loader.getName()), ex); } diff --git a/src/main/java/org/bukkit/util/BlockIterator.java b/src/main/java/org/bukkit/util/BlockIterator.java index 61834b3d..ce2407ff 100644 --- a/src/main/java/org/bukkit/util/BlockIterator.java +++ b/src/main/java/org/bukkit/util/BlockIterator.java @@ -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; diff --git a/src/main/java/org/bukkit/util/BlockVector.java b/src/main/java/org/bukkit/util/BlockVector.java index ded28503..1d5ab4fc 100644 --- a/src/main/java/org/bukkit/util/BlockVector.java +++ b/src/main/java/org/bukkit/util/BlockVector.java @@ -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;
}
}
diff --git a/src/main/java/org/bukkit/util/Vector.java b/src/main/java/org/bukkit/util/Vector.java index d018a066..1d2181da 100644 --- a/src/main/java/org/bukkit/util/Vector.java +++ b/src/main/java/org/bukkit/util/Vector.java @@ -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; } /** |