mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-02 17:32:03 +01:00
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:
parent
5673661da0
commit
bb755bb9a2
9 changed files with 51 additions and 16 deletions
|
@ -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]", "");
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue