Solved How to get head owner

Discussion in 'Spigot Plugin Development' started by kyngs, May 6, 2020.

  1. Are you developing a plugin? Because that is what this forum is for. Webscraping is something entirely different
  2. Yes I am and I need these heads for my plugin.
  3. Not exactly what you are specifically looking for but since you're wanting the information for a plugin you are making I can just give you the code itself.

    This is an example of how to do it
    Code (Text):

        public void findSkullOwner(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
                ItemStack item = player.getInventory().getItemInMainHand();
                if (item.getType() == Material.PLAYER_HEAD) {
                    SkullMeta meta = (SkullMeta) item.getItemMeta();
                    String playerName = meta.getOwningPlayer().getName();
                    UUID playerUUID = meta.getOwningPlayer().getUniqueId();
                    player.sendMessage("The Skull Owner of this head is " + playerName + " with the UUID of " + playerUUID);
    When you left click a player head it will spit out this in chat.

    Good luck and have fun!

    The main take away from this is SkullMeta.
  4. Since you already know the UUID on forehand looking that up is not necessarily, which makes it a bit simpler.
    You can create an ItemStack of type PlayerHead and then set the owner by UUID, like this:
    Code (Java):
    ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD);
    SkullMeta meta = (SkullMeta) playerHead.getItemMeta();
    UUID uuid = UUID.fromString("9db55454-6114-4bf8-aa27-55419d4890c4"); //UUID of player whose head you want
    // give it to the player for example
  5. The problem is I don't know owner UUID
  6. I assumed you wanted the head of the website you cited. The UUID in my example is the one for that head (it is actually inside those summon strings if you look carefully). If you want a generic way of getting a UUID from a playername, please see the resource I cited earlier
  7. The problem is, that UUID is invalid (probbably it is some random id). You can check it yourselves at, but I've found solution for my problem using textures.