mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-09-11 23:28:04 +02:00
Ensure WrappedGameProfile can handle NULL profiles.
We also implement hashCode() ourselves, to avoid Mojang's buggy version that doesn't handle NULL.
This commit is contained in:
parent
4f95b515ae
commit
e23129540c
@ -1,5 +1,7 @@
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
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.
|
||||
* @param profile - the underlying profile.
|
||||
* @param profile - the underlying profile, or NULL.
|
||||
*/
|
||||
public static WrappedGameProfile fromHandle(Object handle) {
|
||||
if (handle == null)
|
||||
return null;
|
||||
return new WrappedGameProfile(handle);
|
||||
}
|
||||
|
||||
@ -46,6 +50,10 @@ public class WrappedGameProfile extends AbstractWrapper {
|
||||
return getProfile().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the underlying GameProfile.
|
||||
* @return The GameProfile.
|
||||
*/
|
||||
private GameProfile getProfile() {
|
||||
return (GameProfile) handle;
|
||||
}
|
||||
@ -76,9 +84,15 @@ public class WrappedGameProfile extends AbstractWrapper {
|
||||
return getProfile().isComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(getProfile());
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
@ -88,7 +102,7 @@ public class WrappedGameProfile extends AbstractWrapper {
|
||||
|
||||
if (obj instanceof WrappedGameProfile) {
|
||||
WrappedGameProfile other = (WrappedGameProfile) obj;
|
||||
return getProfile().equals(other.getProfile());
|
||||
return Objects.equal(getProfile(), other.getProfile());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user