Minecraft heads API??

Discussion in 'Spigot Plugin Development' started by ItzzSebasGamer, Feb 9, 2018.

  1. A head is part of an entire skin. You cannot easily partially change a skin, if at all. If you want someone to remain their old skin, but apply a different head to it, you need to somehow fetch their skin, create a new skin programatically to apply the new head that you want, and then somehow push this skin to Mojang's API. After all of that, you can finally change the skin of a player. In conclusion, you probably want to simply put a PlayerHead on someone's head instead of directly on their skin.

    To achieve this, simply read through this thread: https://www.spigotmc.org/threads/solved-custom-head-texture.74387/
     
  2. Thanks
     
  3. Is the first code passed or what ??
     
  4. public ItemStack getSkull(String url) {
    ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
    if(url.isEmpty())return head;


    SkullMeta headMeta = (SkullMeta) head.getItemMeta();
    GameProfile profile = new GameProfile(UUID.randomUUID(), null);
    byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes());
    profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
    Field profileField = null;
    try {
    profileField = headMeta.getClass().getDeclaredField("profile");
    profileField.setAccessible(true);
    profileField.set(headMeta, profile);
    } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
    e1.printStackTrace();
    }
    head.setItemMeta(headMeta);
    return head;
    }

    The method encodeBase64, not exist
     
  5. you need to do your own work a bit. It seems that you've already given ample information to complete what you're after. It's now all up to you to fully utilize the information given. (there are even a number of threads and resrouces which address what you're after, but I won't list them all becase I feel that you need to learn to do this sort of search yourself.)
     
  6. What are you trying to do? Giving a player head with texture? If so then you all you need is to set the heads owner through skull meta like...
    Code (Text):
    ItemStack skull = new ItemStack(Material.SKULL_ITEM, (short) 3);
    SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
    skullMeta.setOwner("Notch");
    skull.setItemMeta(skullMeta);
    And plz use the "code" button next time so your code is more readable. There is a plus sign when you're writing a message at the top of the text where the code button is.
     
  7. Not all textures have an owner. You can get more textures from the Texture API of Mojang. The sample given in the first thread, the YouTube icon, for instance is a texture that isn't directly linked to a player. Whenever you upload a skin to Mojang's servers, Mojang will store the texture forever in their database from what was seen. This means that if you get the texture from their API, the texture is permanent and will never be changed, unlike using a skin from a player that might change sometime in the future. In fact, all of the websites that contain a database of playerheads don't have these linked to active users.

    So using the .setOwner(String name) is a very insecure way of applying a texture that should be permanent, unless you own a player with that name that has a skin that you will never change. But why bother if you can change the texture permanently with just a bit of reflection?
     
  8. Im say custom head, no player head
     
    • Agree Agree x 1
  9. How i use the api?
     
  10. Code (Text):
    // Skulls with Base64 texture value
    String texture = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMmM2NDVhNDI1OTg3ZjNiN2MyZmFjMDIwNmNlOThiYTVlMjNiOWM0ODUyZmVhNWIxOTc4Zjc0NjdlOGQzMTMifX19";
    ItemStack texturedSkull = ItemUtil.setSkullOwner(head, player.getUniqueId(), textureValue);
    Also make sure to shade it into your jar.
     
  11. Sorry. My bad.
     
  12. Code (Java):

    //Creates an itemsatck of an PlayerSkull
    ItemStack playerskull = new ItemStack(Material.SKULL_ITEM,1, (short) SkullType.PLAYER.ordinal());
    //Creates an variable for meta (if you have more than one itemstack,make different names)
    SkullMeta meta = (SkullMeta) playerskull.getItemMeta();
    //Sets the heads texture,which in this case would be the player viewing the head,in a GUI,for example
    meta.setOwner(player.getName());
    //Links all meta properties to the playerskull itemstack
    playerskull.setItemMeta(meta);
     
    Note: at line 3 (or 6,if you consider the comments), "player.getName()" could be replaced by an player name,like Notch,for Notchs skin.
     
  13. Read please! before post, im say custom head, no player head REAAADDDDDDDDDDDDD
     
  14. Define "Custom heads",then.You can use Marc_IRL's custom heads (https://imgur.com/a/yM0wr) with the method i showed you to use "Custom Heads".
     
  15. This is Spigot plugin development
     

Share This Page