SPIGOT-3553: Add OfflinePlayer based methods to SkullMeta

This commit is contained in:
md_5 2017-09-06 16:14:21 +10:00
parent 178caf9ac2
commit 9e3636d82a

View File

@ -6,7 +6,9 @@ import net.minecraft.server.GameProfileSerializer;
import net.minecraft.server.NBTBase;
import net.minecraft.server.NBTTagCompound;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.serialization.DelegateDeserialization;
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
@ -111,6 +113,21 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
return hasOwner() ? profile.getName() : null;
}
@Override
public OfflinePlayer getOwningPlayer() {
if (hasOwner()) {
if (profile.getId() != null) {
return Bukkit.getOfflinePlayer(profile.getId());
}
if (profile.getName() != null) {
return Bukkit.getOfflinePlayer(profile.getName());
}
}
return null;
}
public boolean setOwner(String name) {
if (name != null && name.length() > MAX_OWNER_LENGTH) {
return false;
@ -125,6 +142,13 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
return true;
}
@Override
public boolean setOwningPlayer(OfflinePlayer owner) {
profile = (owner == null) ? null : new GameProfile(owner.getUniqueId(), owner.getName());
return true;
}
@Override
int applyHash() {
final int original;