Made OfflinePlayer and Player share the same .equals and .hashcode

This commit is contained in:
Nathan Adams 2011-12-12 15:34:49 +00:00
parent 82965eb10f
commit 91ff0b059d
2 changed files with 27 additions and 5 deletions

View File

@ -97,4 +97,26 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
return null;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof OfflinePlayer)) {
return false;
}
OfflinePlayer other = (OfflinePlayer)obj;
if ((this.getName() == null) || (other.getName() == null)) {
return false;
}
return this.getName().equalsIgnoreCase(other.getName());
}
@Override
public int hashCode() {
int hash = 5;
hash = 97 * hash + (this.getName() != null ? this.getName().hashCode() : 0);
return hash;
}
}

View File

@ -4,7 +4,6 @@ import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.LinkedHashMap;
import java.util.Map;
import net.minecraft.server.EntityHuman;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.Packet131ItemData;
import net.minecraft.server.Packet200Statistic;
@ -24,6 +23,7 @@ import org.bukkit.Instrument;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Note;
import org.bukkit.OfflinePlayer;
import org.bukkit.Statistic;
import org.bukkit.World;
import org.bukkit.configuration.serialization.DelegateDeserialization;
@ -160,14 +160,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
if (!(obj instanceof OfflinePlayer)) {
return false;
}
final CraftPlayer other = (CraftPlayer) obj;
if ((this.getName() == null) ? (other.getName() != null) : !this.getName().equals(other.getName())) {
OfflinePlayer other = (OfflinePlayer)obj;
if ((this.getName() == null) || (other.getName() == null)) {
return false;
}
return true;
return this.getName().equalsIgnoreCase(other.getName());
}
public void kickPlayer(String message) {