Archiviert
13
0

Ensure WrappedGameProfile can handle NULL profiles.

We also implement hashCode() ourselves, to avoid Mojang's buggy 
version that doesn't handle NULL.
Dieser Commit ist enthalten in:
Kristian S. Stangeland 2014-01-11 02:24:56 +01:00
Ursprung 4f95b515ae
Commit e23129540c

Datei anzeigen

@ -1,5 +1,7 @@
package com.comphenix.protocol.wrappers; package com.comphenix.protocol.wrappers;
import com.google.common.base.Objects;
import net.minecraft.util.com.mojang.authlib.GameProfile; import net.minecraft.util.com.mojang.authlib.GameProfile;
/** /**
@ -24,9 +26,11 @@ public class WrappedGameProfile extends AbstractWrapper {
/** /**
* Construct a wrapper around an existing game profile. * Construct a wrapper around an existing game profile.
* @param profile - the underlying profile. * @param profile - the underlying profile, or NULL.
*/ */
public static WrappedGameProfile fromHandle(Object handle) { public static WrappedGameProfile fromHandle(Object handle) {
if (handle == null)
return null;
return new WrappedGameProfile(handle); return new WrappedGameProfile(handle);
} }
@ -46,6 +50,10 @@ public class WrappedGameProfile extends AbstractWrapper {
return getProfile().getName(); return getProfile().getName();
} }
/**
* Retrieve the underlying GameProfile.
* @return The GameProfile.
*/
private GameProfile getProfile() { private GameProfile getProfile() {
return (GameProfile) handle; return (GameProfile) handle;
} }
@ -76,9 +84,15 @@ public class WrappedGameProfile extends AbstractWrapper {
return getProfile().isComplete(); return getProfile().isComplete();
} }
@Override
public String toString() {
return String.valueOf(getProfile());
}
@Override @Override
public int hashCode() { public int hashCode() {
return getProfile().hashCode(); // Mojang's hashCode() is broken, it doesn't handle NULL id or name. So we implement our own
return Objects.hashCode(getId(), getName());
} }
@Override @Override
@ -88,7 +102,7 @@ public class WrappedGameProfile extends AbstractWrapper {
if (obj instanceof WrappedGameProfile) { if (obj instanceof WrappedGameProfile) {
WrappedGameProfile other = (WrappedGameProfile) obj; WrappedGameProfile other = (WrappedGameProfile) obj;
return getProfile().equals(other.getProfile()); return Objects.equal(getProfile(), other.getProfile());
} }
return false; return false;
} }