From 91ff0b059d441c3e9bcdcc3c962713e7962876b5 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Mon, 12 Dec 2011 15:34:49 +0000 Subject: [PATCH] Made OfflinePlayer and Player share the same .equals and .hashcode --- .../craftbukkit/CraftOfflinePlayer.java | 22 +++++++++++++++++++ .../craftbukkit/entity/CraftPlayer.java | 10 ++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java index 55b2f1ef66..68789a9f8e 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java @@ -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; + } } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index efed45acdd..ba2757bf9e 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -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) {