Paper 1.21 Custom Skulls

DevSnx

New member
Jul 17, 2024
1
0
1
Hey guys, my method dont set the Skin from URL
My Try

SkinURL
ItemSkulls.getSkull2("https://textures.minecraft.net/text...94500fc6402dafd17f3b4b18f1f9b2c8c01ed9adadccb", 1, "§8» §aVote-Belohnung");


Java:
    public static ItemStack getSkull1(String skinURL, int amount, String name) {
        ItemStack skull = new ItemStack(Material.PLAYER_HEAD, 1);
        skull.editMeta(itemMeta -> {
            SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
            PlayerProfile playerProfile = Bukkit.createProfile(UUID.randomUUID());
            PlayerTextures playerTextures = playerProfile.getTextures();
            try {
                playerTextures.setSkin(new URL(skinURL));
            }catch (MalformedURLException exception){
                throw new RuntimeException(exception);
            }

            playerProfile.setTextures(playerTextures);
            skullMeta.setPlayerProfile(playerProfile);
        });

        return skull;
    }
 
Version Output
1.21

Andre_601

New member
Feb 8, 2022
22
6
3
From the Javadoc of editMeta:
Calling this method or any other meta-related method of the ItemStack class (such as getItemMeta(), addItemFlags(ItemFlag...), lore(), etc.) from inside the consumer is disallowed and will produce undefined results or exceptions.
So it may be the fact that you are using the getItemMeta method from within the editMeta method itself, which if I understand the docs right is not supported and in your case probs fails silently.

Looking further at the docs can I see the existance of a editMeta(Class<M>, Consumer<? super M>) where you can define the specific meta you want to edit (Which in your case is SkullMeta), eliminating the need to cast this stuff...
 
  • Like
Reactions: DevSnx