1.15.2 ItemStack Player Head

Discussion in 'Spigot Plugin Development' started by SchnellfeuerXD, May 18, 2020.

  1. Hey I´ve been working on a BaGui Plugin with the Playerheads. But i don´t know how the Material.Player_Head
    should get the skin of the player.

    Code (Text):

    package de.grafplaiz.bangui.inventorys;

    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;

    public class SpielerAuswahl {
       
        public void openSpieler (Player player) {
            ArrayList<Player> player_list = new ArrayList<>(player.getServer().getOnlinePlayers());
            Inventory bangui = Bukkit.createInventory(player, 45, ChatColor.BLUE + "Spieler Liste");
            player.openInventory(bangui);
           
           
            //Spielernamen und Köpfe
           
            for(int i = 0; i < player_list.size(); i++) {
                ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD, 1);
                ItemMeta meta = playerHead.getItemMeta();
                meta.setDisplayName(player_list.get(i).getDisplayName());
                ArrayList<String> lore = new ArrayList<>();
                lore.add(ChatColor.AQUA + "Hp: " + player_list.get(i).getHealth());
                meta.setLore(lore);
                playerHead.setItemMeta(meta);
                bangui.addItem(playerHead);
               
                ItemStack barrier = new ItemStack(Material.BARRIER, 1);
                ItemMeta barrier_meta = barrier.getItemMeta();
                barrier_meta.setDisplayName(ChatColor.RED + "Schließen");
                barrier.setItemMeta(barrier_meta);
                bangui.setItem(44, barrier);
            }
        }
       
    }
     
    Maybe you can help me, I know how to skript a head plugin but i dont know how to do this.
    Maybe you have a good tutrial or an explination for me!

    Sincerely SchnellfeuerXD
     
  2. SkullMeta has a setOwningPlayer() method which gives a skull a player's skin.

    See: SkullMeta
     
  3. Thank you but how i write this in my code. I´m confused at the moment.
     
  4. Code (Java):
    SkullMeta meta = (SkullMeta) playerHead.getItemMeta();
    This is how you get the SkullMeta if I remember correctly, which you can then use to set the owner of the skull.
     
  5. Code (Text):

                ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD, 1);
                SkullMeta meta = (SkullMeta) playerHead.getItemMeta();
                meta.setDisplayName(player_list.get(i).getDisplayName());
                ArrayList<String> lore = new ArrayList<>();
                lore.add(ChatColor.AQUA + "Hp: " + player_list.get(i).getHealth());
                meta.setLore(lore);
                playerHead.setItemMeta(meta);
                bangui.addItem(playerHead);
             
                ItemStack barrier = new ItemStack(Material.BARRIER, 1);
                ItemMeta barrier_meta = barrier.getItemMeta();
                barrier_meta.setDisplayName(ChatColor.RED + "Schließen");
                barrier.setItemMeta(barrier_meta);
                bangui.setItem(44, barrier);
     
    If i use it like this it is not working :(
     
  6. This should work (untested code):

    Code (Text):

    ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
    SkullMeta meta = (SkullMeta) skull.getItemMeta();
    meta.setOwner(//name);
    skull.setItemMeta(meta);
     
     
  7. Be sure to use SkullMeta#setOwningPlayer(), as SkullMeta#setOwner() is deprecated.
     
    • Agree Agree x 1
  8. Woops, my bad. Still a bit used to 1.12.2.