1.14.4 Skull CustomTexture

Discussion in 'Spigot Plugin Development' started by julien0312, Feb 2, 2020.

  1. Hello, I'm looking to make a getSkullOwner in multi-version but I admit to having a little trouble with the getOfflinePlayer of 1.14 if you can help me it would be great :D

    Code (Text):

    public static ItemStack getSkullOwner(String owner) {
        Material M = UMaterial.SKELETON_SKULL_ITEM.getMaterial();
        ItemStack itemStack = new ItemStack(M, 1, (short) SkullType.PLAYER.ordinal());
        SkullMeta itemMeta = (SkullMeta)itemStack.getItemMeta();
        if(Versionable.FOURTEEN || Versionable.FIFTEEN){
            OfflinePlayer player = Bukkit.getOfflinePlayer(owner);
            itemMeta.setOwningPlayer(player);
        }else{
            itemMeta.setOwner(owner);
        }
        itemStack.setItemMeta(itemMeta);
        return itemStack;
    }
     
  2. So... What is the actual problem you're having? Does it give any errors..?
     
    • Friendly Friendly x 1
  3. The problem is with the textures, they do not appear from 1.14 and I have no error
     
  4. Can you debug this for me? You said you had trouble with getting the OfflinePlayer. Can you try to console log the OfflinePlayer and see if it actually is something which contains data? I think the problem is is that you're trying to get an OfflinePlayer from a String. But from my experience, I've noticed that it's better to get the OfflinePlayer via the player's UUID. Can you try getting the OfflinePlayer via the UUID and see if the problem still persists?
     
  5. This code works greatly on 1.12+ (as long as i remember), may it help you?

    Code (Java):
    package yourpackage;

    import java.lang.reflect.Field;
    import java.util.UUID;

    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;

    import com.mojang.authlib.GameProfile;
    import com.mojang.authlib.properties.Property;
    import com.mojang.authlib.properties.PropertyMap;

    public class Utility {
       
        public static ItemStack getSkullAsItem(String b64stringtexture) {
            GameProfile profile = new GameProfile(UUID.randomUUID(), null);
            PropertyMap propertyMap = profile.getProperties();
            if (propertyMap == null) {
                throw new IllegalStateException("Profile doesn't contain a property map");
            }
            propertyMap.put("textures", new Property("textures", b64stringtexture));
            ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1);
            ItemMeta headMeta = head.getItemMeta();
            Class<?> headMetaClass = headMeta.getClass();
            try {
                getField(headMetaClass, "profile", GameProfile.class, 0).set(headMeta, profile);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            head.setItemMeta(headMeta);
            return head;
        }
       
        private static <T> Field getField(Class<?> target, String name, Class<T> fieldType, int index) {
            for (final Field field : target.getDeclaredFields()) {
                if ((name == null || field.getName().equals(name)) && fieldType.isAssignableFrom(field.getType()) && index-- <= 0) {
                    field.setAccessible(true);
                    return field;
                }
            }

            if (target.getSuperclass() != null)
                return getField(target.getSuperclass(), name, fieldType, index);
            throw new IllegalArgumentException("Cannot find field with type " + fieldType);
        }
    }