Solved Custom Heads Texture Value

Discussion in 'Spigot Plugin Help' started by BrainRTP, Jul 18, 2018.

Thread Status:
Not open for further replies.
  1. Hello there.

    I just want to ask you guys If you could help me with how to get head value which uses to identify texture of the head. I'm writing my own plugin and I want to check this value to remove specify head from player's inventory, but I don't know how to get this value.

    By the value I mean this:
    Screenshot_65.png

    P.S. Sorry If I'm too stupid to find this.
     
  2. Each skull item is binded with SkullMeta, the base interface of the bukkit implementation that deals with skull item meta. This specific meta has a gameprofile which it uses to determine the texture properties. You can use reflection to access the field, or grab the owning player and access the gameprofile from there.

    Code (Java):

    package org.bukkit.craftbukkit.v1_12_R1.inventory;

    import com.google.common.base.Predicate;
    import com.google.common.collect.ImmutableMap.Builder;
    import com.mojang.authlib.GameProfile;
    import java.util.Locale;
    import java.util.Map;
    import java.util.UUID;
    import net.minecraft.server.v1_12_R1.GameProfileSerializer;
    import net.minecraft.server.v1_12_R1.NBTBase;
    import net.minecraft.server.v1_12_R1.NBTTagCompound;
    import net.minecraft.server.v1_12_R1.TileEntitySkull;
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.OfflinePlayer;
    import org.bukkit.configuration.serialization.DelegateDeserialization;
    import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftMetaItem.ItemMetaKey;
    import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftMetaItem.SerializableMeta;
    import org.bukkit.inventory.meta.SkullMeta;

    @DelegateDeserialization(SerializableMeta.class)
    class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
        static final ItemMetaKey SKULL_PROFILE = new ItemMetaKey("SkullProfile");
        static final ItemMetaKey SKULL_OWNER = new ItemMetaKey("SkullOwner", "skull-owner");
        static final int MAX_OWNER_LENGTH = 16;
        private GameProfile profile;

        CraftMetaSkull(CraftMetaItem meta) {
            super(meta);
            if (meta instanceof CraftMetaSkull) {
                CraftMetaSkull skullMeta = (CraftMetaSkull)meta;
                this.profile = skullMeta.profile;
            }
        }

        CraftMetaSkull(NBTTagCompound tag) {
            super(tag);
            if (tag.hasKeyOfType(SKULL_OWNER.NBT, 10)) {
                this.profile = GameProfileSerializer.deserialize(tag.getCompound(SKULL_OWNER.NBT));
            } else if (tag.hasKeyOfType(SKULL_OWNER.NBT, 8) && !tag.getString(SKULL_OWNER.NBT).isEmpty()) {
                this.profile = new GameProfile((UUID)null, tag.getString(SKULL_OWNER.NBT));
            }

        }

        CraftMetaSkull(Map<String, Object> map) {
            super(map);
            if (this.profile == null) {
                this.setOwner(SerializableMeta.getString(map, SKULL_OWNER.BUKKIT, true));
            }

        }

        void deserializeInternal(NBTTagCompound tag) {
            if (tag.hasKeyOfType(SKULL_PROFILE.NBT, 10)) {
                this.profile = GameProfileSerializer.deserialize(tag.getCompound(SKULL_PROFILE.NBT));
            }

        }

        void serializeInternal(Map<String, NBTBase> internalTags) {
            if (this.profile != null) {
                NBTTagCompound nbtData = new NBTTagCompound();
                GameProfileSerializer.serialize(nbtData, this.profile);
                internalTags.put(SKULL_PROFILE.NBT, nbtData);
            }

        }

        void applyToItem(final NBTTagCompound tag) {
            super.applyToItem(tag);
            if (this.profile != null) {
                NBTTagCompound owner = new NBTTagCompound();
                GameProfileSerializer.serialize(owner, this.profile);
                tag.set(SKULL_OWNER.NBT, owner);
                TileEntitySkull.b(this.profile, new Predicate<GameProfile>() {
                    public boolean apply(GameProfile input) {
                        NBTTagCompound owner = new NBTTagCompound();
                        GameProfileSerializer.serialize(owner, input);
                        tag.set(CraftMetaSkull.SKULL_OWNER.NBT, owner);
                        return false;
                    }
                });
            }

        }

        boolean isEmpty() {
            return super.isEmpty() && this.isSkullEmpty();
        }

        boolean isSkullEmpty() {
            return this.profile == null;
        }

        boolean applicableTo(Material type) {
            switch($SWITCH_TABLE$org$bukkit$Material()[type.ordinal()]) {
            case 396:
                return true;
            default:
                return false;
            }
        }

        public CraftMetaSkull clone() {
            return (CraftMetaSkull)super.clone();
        }

        public boolean hasOwner() {
            return this.profile != null && this.profile.getName() != null;
        }

        public String getOwner() {
            return this.hasOwner() ? this.profile.getName() : null;
        }

        public OfflinePlayer getOwningPlayer() {
            if (this.hasOwner()) {
                if (this.profile.getId() != null) {
                    return Bukkit.getOfflinePlayer(this.profile.getId());
                }

                if (this.profile.getName() != null) {
                    return Bukkit.getOfflinePlayer(this.profile.getName());
                }
            }

            return null;
        }

        public boolean setOwner(String name) {
            if (name != null && name.length() > 16) {
                return false;
            } else {
                if (name == null) {
                    this.profile = null;
                } else {
                    this.profile = (GameProfile)TileEntitySkull.skinCache.getIfPresent(name.toLowerCase(Locale.ROOT));
                    if (this.profile == null) {
                        this.profile = new GameProfile((UUID)null, name);
                    }
                }

                return true;
            }
        }

        public boolean setOwningPlayer(OfflinePlayer owner) {
            this.profile = owner == null ? null : new GameProfile(owner.getUniqueId(), owner.getName());
            return true;
        }

        int applyHash() {
            int original;
            int hash = original = super.applyHash();
            if (this.hasOwner()) {
                hash = 61 * hash + this.profile.hashCode();
            }

            return original != hash ? CraftMetaSkull.class.hashCode() ^ hash : hash;
        }

        boolean equalsCommon(CraftMetaItem meta) {
            if (!super.equalsCommon(meta)) {
                return false;
            } else if (!(meta instanceof CraftMetaSkull)) {
                return true;
            } else {
                CraftMetaSkull that = (CraftMetaSkull)meta;
                return this.hasOwner() ? that.hasOwner() && this.profile.equals(that.profile) : !that.hasOwner();
            }
        }

        boolean notUncommon(CraftMetaItem meta) {
            return super.notUncommon(meta) && (meta instanceof CraftMetaSkull || this.isSkullEmpty());
        }

        Builder<String, Object> serialize(Builder<String, Object> builder) {
            super.serialize(builder);
            return this.hasOwner() ? builder.put(SKULL_OWNER.BUKKIT, this.profile.getName()) : builder;
        }
    }
     
  3. Thank you.
     
Thread Status:
Not open for further replies.