#Issue with creating custom player heads

1 messages · Page 1 of 1 (latest)

warm coral
#

Hello, I'm programming a function in spigot which basically returns a player head with a skin with provided texturevalue, but it doesn't work and i don't really know how to fix it/do it at all. Can someone help me out?
Code I came up with so far:

        ItemStack customHead = new ItemStack(Material.PLAYER_HEAD);
        SkullMeta meta = (SkullMeta) customHead.getItemMeta();
        try {
            PlayerProfile owner = HLevels.getPlugin().getServer().createPlayerProfile(textureValue);
            meta.setOwnerProfile(owner);
            customHead.setItemMeta(meta);
            return customHead;
        } catch (NullPointerException e)
        {
            return null;
        }
    }```
silk quartz
#

?notworking

unreal grailBOT
#

"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.

silk quartz
#

also why are you catching a NPE?

warm coral
silk quartz
#

Spigot 1.18.1 added the new PlayerProfiles class, which finally allows us to use custom heads without needing any reflection! You can obtain them as normal items, or actually place them down into the world. I’ll show you how both works: Creating a new PlayerProfile First, we gotta create a new PlayerProfile object. To do so,...

warm coral
#

doesn't throw exception though

silk quartz
#

yeah but if you just catch the exception without printing it out, then you won't even know there was an exception

#

the blog post explains everything needed to turn the info from the website into a an actual head

silk quartz
#

np!

warm coral