How to have custom heads in a GUI and give a player a custom head

Discussion in 'Spigot Plugin Development' started by xUbalubex, Aug 6, 2018.

  1. The title itself is self explanatory. I want to have a gui with a head. (This I know how to do) And when you click the head it will give you it. Although, the head I want has an ID (Its not an actual player its a custom head) so the problem is that I have no clue on how to use the ID instead of the skullowner's playername. Help would be great!

    Code (Text):
    package me.bukkit.ubalube;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.SkullMeta;
    import org.bukkit.plugin.Plugin;

    public class Menu1 implements Listener {
       
        private Inventory inv;
     
     
        @SuppressWarnings("deprecation")
        public Menu1(Plugin p) {
                inv = Bukkit.getServer().createInventory(null, 9, "┬žeMy Menu Name Here");
             
                ItemStack skull = new ItemStack(397, 1, (short) 3);
                SkullMeta meta = (SkullMeta) skull.getItemMeta();
                meta.setOwner("I need a UUID not a player");
                meta.setDisplayName(ChatColor.AQUA + "The Cusom Head Name");
                skull.setItemMeta(meta);
             
             
                inv.setItem(2, skull);
             
                Bukkit.getServer().getPluginManager().registerEvents(this, p);
             
        }
     
        public void show(Player p) {
                p.openInventory(inv);
    }
     
        @EventHandler
        public void onInventoryClick1(InventoryClickEvent e) {
                if (!e.getInventory().getName().equalsIgnoreCase(inv.getName())) return;
                if (e.getCurrentItem().getItemMeta() == null) return;
                if (e.getCurrentItem().getItemMeta().getDisplayName().contains("I need a UUID not a player")) {
                        e.setCancelled(true);
                        //Give the player the head
                    }
            }
    }

    Code (Text):
    package me.bukkit.ubalube;

    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;

    public class main extends JavaPlugin implements Listener
    {
     
        private Menu1 menu;
     
        public void onEnable()
        {
            getLogger().info("Plugin Is Enabled!");
            this.saveDefaultConfig();
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            menu = new Menu1(this);
        }

        public void onDisable() {
        }

        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
     
        if(cmd.getName().equalsIgnoreCase("eh"))
        {
            Player p = (Player) sender;
         
            menu.show(p);
         
            return true;
        }

        return false;
        }

    }

    Sidenote: https://bukkit.org/threads/create-your-own-custom-head-texture.424286/ <-- this url did not help me. I am using heads from the head database
     
    #1 xUbalubex, Aug 6, 2018
    Last edited: Aug 6, 2018
  2. What ID you're talking about exactly?
     
  3. Okay so heres the head im trying to do : https://minecraft-heads.com/custom/heads/food-drinks/21868-starbucks-coffee

    At the very bottom, it says the custom head id is: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZTU5ZmI5NTdiNzM2MzBiMTczYzIyNTJkNTZkODI5NzVmZGYwZThkZjVjMGMzZjNhNTE0MjU4NWExYjM3MDA5MyJ9fX0=
     
  4. Ah now i understand.
    You got a texture link only, without UUID. The texture maybe even haven't a player UUID anymore.

    The "ID" you posted is not an ID.
    It's a base64 encoded string. Decode it and you'll see:
    Code (json (Unknown Language)):
    {"textures":{"SKIN":{"url":"http://textures.minecraft.net/texture/e59fb957b73630b173c2252d56d82975fdf0e8df5c0c3f3a5142585a1b370093"}}}
    So this is the acutal texture you're after http://textures.minecraft.net/textu...2252d56d82975fdf0e8df5c0c3f3a5142585a1b370093.

    The JSON structure is documented here: https://minecraft.gamepedia.com/Player.dat_format#Player_Heads

    However the bukkit API does not support to set such head textures without UUID. You got no player UUID, neither a name, because there might be no active player account to this texture anymore.

    Once you get it managed to apply the structure as linked in MC wiki, you can choose any random UUID and Name, MC won't check it, if the texture is given.

    So you'll need to read through decompiled NMS code of the item.
     
    • Informative Informative x 1
  5. Update:
    I got some boredom and puzzeled something together for you @xUbalubex
    Try this:
    Code (Java):
    public ItemStack applySkullTexture() {
        net.minecraft.server.v1_13_R1.ItemStack item = CraftItemStack.asNMSCopy(new ItemStack(Material.PLAYER_HEAD, 1));
        NBTTagCompound tag;
        if (item.hasTag()) {
            tag = item.getTag();
        } else {
            tag = new NBTTagCompound();
        }
        NBTTagCompound skullOwner = new NBTTagCompound();
        NBTTagCompound properties = new NBTTagCompound();
        NBTTagList textures = new NBTTagList();
        NBTTagCompound texture = new NBTTagCompound();

        texture.setString("Value", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZTU5ZmI5NTdiNzM2MzBiMTczYzIyNTJkNTZkODI5NzVmZGYwZThkZjVjMGMzZjNhNTE0MjU4NWExYjM3MDA5MyJ9fX0=");
        textures.add(texture);
        properties.set("textures", textures);
        skullOwner.set("Properties", properties);
        tag.set("SkullOwner", skullOwner);

        item.setTag(tag);
        return CraftItemStack.asBukkitCopy(item);
    }
     
    • Informative Informative x 4
    • Useful Useful x 1