Make skulls pretend to only use names like before 1.7.8.

Any new API here needs more thought, skulls require a name but OfflinePlayer
is not guaranteed to have one. There is a Mojang approved way to get a
complete profile from a name but not from a UUID so for now just pretend
this still only uses names.
This commit is contained in:
Travis Watkins 2014-04-17 08:41:29 -05:00
parent 6ad36f09e5
commit a8d5c1224f

View File

@ -14,6 +14,7 @@ import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftPlayer;
public class CraftSkull extends CraftBlockState implements Skull {
private static final int MAX_OWNER_LENGTH = 16;
private final TileEntitySkull skull;
private GameProfile profile;
private SkullType skullType;
@ -146,31 +147,23 @@ public class CraftSkull extends CraftBlockState implements Skull {
}
public String getOwner() {
return profile.getName();
return hasOwner() ? profile.getName() : null;
}
public boolean setOwner(String name) {
return false;
}
public OfflinePlayer getPlayer() {
return MinecraftServer.getServer().server.getOfflinePlayer(profile);
}
public boolean setPlayer(OfflinePlayer player) {
GameProfile profile;
if (player instanceof CraftPlayer) {
profile = ((CraftPlayer) player).getProfile();
} else if (player instanceof CraftOfflinePlayer) {
profile = ((CraftOfflinePlayer) player).getProfile();
} else {
if (name == null || name.length() > MAX_OWNER_LENGTH) {
return false;
}
GameProfile profile = MinecraftServer.getServer().getUserCache().a(name);
if (profile == null) {
return false;
}
if (skullType != SkullType.PLAYER) {
skullType = SkullType.PLAYER;
}
this.profile = profile;
return true;
}