Adding a players head into an inventory (GUI)

Discussion in 'Spigot Plugin Development' started by DecisionsYT, May 29, 2016.

  1. Hey!

    So, I've created an inventory. Inside in one of the slots, it needs to be a targets head. The command is /punish (target) so it will show that targets head.

    When trying, it just shows the standard Steve head, and not the targets head... Any suggestions?

    CODE:

    Code (Text):

                            ItemStack skull = new ItemStack (Material.SKULL_ITEM, 1, (short) 3);
                            SkullMeta skullmeta = (SkullMeta) skull.getItemMeta();
                            skullmeta.setOwner(target.getName());
                            skullmeta.setDisplayName("§bPunishing:");
                            skullmeta.setLore(Arrays.asList(new String[] { "§3" + target.getName() }));
                            skull.setItemMeta(skullmeta);
                            inv.setItem(0, skull);
     
  2. Easiest way is just convert a playerHead to old version minecraft way... first of all once you create skull you must know that .setOwner() works mostly with the old Easy way

    Code (Text):
                ItemStack item = new ItemStack(Material.SKULL_ITEM);
                SkullMeta sk = (SkullMeta) item.getItemMeta();
                sk.setOwner(p.getName())
                sk.setLore(desc);
                item.setItemMeta(sk);
                inv.addItem(item);
     
  3. I'll test now
     
  4. anyway your most bad mistake was you gave it ItemIDData... the short thinggy... you shouldn't because its a skull... that's how its works todays days
     
  5. Ahh okay


    Sent from my iPod touch using Tapatalk
     
  6. I just use this method since I don't have to re-write code all the time :p

    Code (Text):
    public ItemStack getSkull(Player player, String displayName, List<String> lore){

            ItemStack itemStack = new ItemStack(Material.SKULL_ITEM);
            SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta();

            skullMeta.setOwner(player.getName());
            skullMeta.setDisplayName(displayName);
            skullMeta.setLore(lore);

            itemStack.setItemMeta(skullMeta);

            return itemStack;

        }
     
    • Creative Creative x 1
  7. Great Idea, Shorter way for coding and much funnier way to use!
     
  8. Got a skeleton head then.

    the public ItemStack getSkull was giving errors, so I removed it
     
  9. is your server is on online-mode: true?
     
  10. It's set at "online-mode: true"
     
  11. CURRENT CODE:

    Code (Text):

                                 ItemStack skull = new ItemStack(Material.SKULL_ITEM);
                                SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();

                                skullMeta.setOwner(player.getName());
                                skullMeta.setDisplayName("§bPunishing:");
                                skullMeta.setLore(Arrays.asList(new String[] { "§3" + target.getName() }));

                                skull.setItemMeta(skullMeta);
                                inv.setItem(0, skull);
     
  12. @DecisionsYT

    this is what I would recommend for you -
    Code (Text):

    ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
                                SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();

                                skullMeta.setOwner(player.getName());
                                skullMeta.setDisplayName("§bPunishing:");
                                skullMeta.setLore(Arrays.asList(new String[] { "§3" + target.getName() }));

                                skull.setItemMeta(skullMeta);
                                inv.setItem(0, skull);
     
     
  13. Nope.
     
  14. Very useful answer, thanks.

    Don't be lazy and tell us what happens etc.
     
  15. The same results as all the others, just comes up as a Steve head.
     
  16. It's running Spigot 1.8.8
     
  17. hmm, idk then, this is my exact code -
    Code (Text):
    ItemStack s = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
                        SkullMeta m = (SkullMeta) s.getItemMeta();
                        m.setOwner(p.getName());
                        m.setDisplayName(ChatColor.DARK_GRAY + "Hello, " + ChatColor.LIGHT_PURPLE + p.getName());
                        m.setLore(Arrays.asList(ChatColor.GRAY + "Welcome to the",
                                ChatColor.GRAY + "SoulKraft Trampoline Settings!",
                                ChatColor.BLUE + "Custom Made by minecrft"));

                        s.setItemMeta(m);
                        Main.setItem(4, s);
    and it works fine for me
     
  18. Ahh 1.8.8 might have something to do with it? I'm not sure just a guess
     
  19. @DecisionsYT could I have the full code (pm) I could try and help you there?