Solved Bukkit Custom head (no texture :c)

Discussion in 'Plugin Development' started by MadMarvin, Jan 25, 2020.

Thread Status:
Not open for further replies.
  1. Hey Guys,
    I want to create a Plugin which give me a custom Head.
    I know to use SKULL_ITEM but there is no such SKULL_ITEM just LEGACY_SKULL_ITEM.
    I just use LEGACY_SKULL_ITEM but it throw me an NoSuchFieldError here is my Code.

    Code:
    package nightmaremc.madmarvin.mysteryboxes.customheads;
    
    import java.lang.reflect.Field;
    import java.util.UUID;
    
    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.SkullMeta;
    
    import com.mojang.authlib.GameProfile;
    import com.mojang.authlib.properties.Property;
    
    public class HeadsMain {
       
        @SuppressWarnings("deprecation")
        public static ItemStack createSkull(String url, String name) {
           
            ItemStack head = new ItemStack(Material.LEGACY_SKULL_ITEM, 1, (short)3);
            if(url.isEmpty()) return head;
    
            SkullMeta headMeta = (SkullMeta) head.getItemMeta();
            GameProfile profile = new GameProfile(UUID.randomUUID(), null);
           
            profile.getProperties().put("textures", new Property("textures", url));
           
            try {
                Field profileField = headMeta.getClass().getDeclaredField("profile");
                profileField.setAccessible(true);
                profileField.set(headMeta, profile);
            } catch (IllegalArgumentException|NoSuchFieldException|SecurityException|IllegalAccessException error) {
                error.printStackTrace();
            }
           
           
            return head;
        }
    
         public static ItemStack getHead(String name) {
             for(Heads head : Heads.values()) {
                 if(head.getName().equals(name)) {
                     return head.getItemStack();
                 }
             }
             return null;
         }
    
       
    }
    Code:
    package nightmaremc.madmarvin.mysteryboxes.customheads;
    
    import org.bukkit.inventory.ItemStack;
    
    public enum Heads {
    
        VIP("MjQzNDM5ODdiNzg2OTY0ZGE2MGY1NTEwNmE0MzViYTUzY2I3OGVmMDBiMTA2Njk0MzM3MTJhZmU0YjZmYjU0NiJ9fX0=","vip"),
        LEGEND("YmUwMDJkOTc3MjNiOGNjOTgwMmQzMGZlOGU0Y2VmMzYxZTU2Y2YyZTQ5YWU5MWYyNzRkYTcyZjQ3ODEzNDExOCJ9fX0=","legend"),
        MASTER("MjE4MTJiNGUwZjAxYmIxOTM3ZGY5Mzg5ZmU2N2UyNWZhNWQ4NzYxMjQ4NTk4MzcwMTZjNDUxNTRiZWQzY2QxZSJ9fX0=","master"),
        BOSS("MTA2ZWExMDRjYjliZTcwM2NjZWQxYjFmNTY1Mjg2NzUyZTI3MTc1MmM1YWM4NWU4MTEzYjNlMmRjNDM1MmMyMCJ9fX0=","boss");
       
        private ItemStack item;
        private String idTag;
        private String prefix = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUv";
       
        private Heads(String texture, String id) {
            item = HeadsMain.createSkull(prefix + texture, id);
            idTag = id;
        }
       
        public ItemStack getItemStack() {
            return item;
        }
       
        public String getName() {
            return idTag;
        }
    }
    
    I tried to use PLAYER_HEAD but it didnt work :/

    Any ideas?

    ~MadMarvin

    Sorry for my bad English XD
     
  2. Offline

    timtower Administrator Administrator Moderator

    @MadMarvin Are your Bukkit.jar and server version the same?
     
  3. I use the bukkit-lib.jar it works for versions from 1.8-1.12 (Tested) An the craftbukkit-1.12.jar
     
  4. Offline

    timtower Administrator Administrator Moderator

    @MadMarvin The legacy stuff is from 1.13 though
     
  5. I use the normal Bukkit-lib.jar for all things and the CrafzBukkit.jar for the GameProfile, because this isnt in the bukkit-lib.jar . My Server still runs on 1.8
     
  6. Offline

    timtower Administrator Administrator Moderator

    @MadMarvin Then get a 1.8 jar for both.
    Then you won't be able to use the wrong enum values.
     
  7. I started to search a bukkit-lib.jar for 1.8 but i didn't find it...
     
  8. Offline

    timtower Administrator Administrator Moderator

    Why not update then?
     
  9. I want to kiss your Eyebrow. Now it works :D I get a Head but its an steve(no texture)? Can you help me?

    Everytime i give me the head its an Steve with no textures... Anyone have an Idea why? Its annoying :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 25, 2020
  10. Offline

    Zombie_Striker

    This is why. The first argument is supposed to be just the URL, but you are providing the URL and a prefix. Remove the prefix to show the skin.
     
  11. Does not work: / As you can see, the variable prefix is not a prefix but only the part that is the same for everyone

    Code:
    private String prefix = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUv";
       
    Bumb

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 26, 2020
  12. Offline

    Zombie_Striker

    @MadMarvin
    If prefix is the texture (BTW: since its not a prefix, you should use a different name), then what does "texture" equal?
     
  13. Texture is the second part of the minecraft skin url
     
Thread Status:
Not open for further replies.

Share This Page