From 9e3636d82a294ae9eaa1ba355765e1e471c66a6c Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 6 Sep 2017 16:14:21 +1000 Subject: [PATCH] SPIGOT-3553: Add OfflinePlayer based methods to SkullMeta --- .../craftbukkit/inventory/CraftMetaSkull.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java index b9c5447249..fbc16890c8 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java @@ -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;