Adding a head in a GUI

Discussion in 'Plugin Development' started by MrPowWow, Jun 8, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    MrPowWow

    Hello, I am wanting to know how to add a player's head in a GUI.
    Though it may be a bit confusing to understand here's what I'm looking to do.

    /remove <playersname>: Would remove the players head from the inventory of heads
    /add <playersname>: add the players head to the inventory of heads
    /heads: to veiw the heads (if the inventory is full you'll be able to click next page or back page)

    If I could be provided with a hand that'll be great. Thank you.
     
  2. Offline

    Zombie_Striker

    @MrPowWow
    Head items are the same as regular items. To add custom heads, create a new itemstack that is a SKULL_ITEM. After that , get the item meta and cast it to a SkullMeta. From there, set the owner by using SkullMeta#setOwner(player).

    After you set that up, adding and removing the heads is as simple as getting the inventory system and using Inventory.add and Inventory.removeItem.
     
  3. Offline

    YoloSanta

    Would this be an example to you ?
    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent e) {
    3. ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
    4.  
    5. SkullMeta meta = (SkullMeta) skull.getItemMeta();
    6. meta.setOwner(e.getPlayer().getName());
    7. meta.setDisplayName(ChatColor.GREEN + e.getPlayer().getName() + "'s Head!");
    8. skull.setItemMeta(meta);
     
  4. Offline

    Zombie_Striker

    @YoloSanta
    Do not spoonfeed. Here is why (from the read-me)
     
    RcExtract likes this.
  5. Offline

    MrPowWow

    I know how to add things into the inventory. I'm looking to see how to add onto it. For an example. When I type /add it would add the head in slot 1. /add again It'll automatically detect that slot 1 is being used so it'll use slot 2 instead.
     
  6. @MrPowWow
    And Inventory.addItem() doesn't do this?
     
  7. Offline

    MrPowWow

    Sorry I'm a bit confused.
    This is what I have for the command
    Code:
        if (cmd.getName().equalsIgnoreCase("addhead")) {
                  ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
                 
                  SkullMeta meta = (SkullMeta) skull.getItemMeta();
                  meta.setOwner(p.getName());
                  meta.setDisplayName(ChatColor.GREEN + p.getName() + "'s head!");
                  skull.setItemMeta(meta);
                servers.addItem(skull); // error I'm wanting to add the skull into the head inventory
             
               }
            }

    Here's the void

    Code:
    public static void openViewHeads(Player p)
      {
        heads = Bukkit.getServer().createInventory(p, 5*9, ChatColor.GOLD + "View Heads");
    
       
    
    
           
            ItemStack z = new ItemStack(Material.REDSTONE_LAMP_ON, 1, DyeColor.GRAY.getData());
            ItemMeta zm = z.getItemMeta();
            ArrayList<String> zl = new ArrayList();
            zm.setDisplayName("Next Page");
            zl.add(" ");
            zm.setLore(zl);
            z.setItemMeta(zm);
       
            selector.setItem(9, z);
        
       
        p.openInventory(heads);
      }
    and the head inventory
    Code:
    public static Inventory heads;
    Thank you all for the help :)
     
  8. Offline

    MrPowWow

  9. Offline

    YoloSanta

    What is it your confused about ?
     
  10. Offline

    MrPowWow

    I'm wanting to make it where I can add player heads into the GUI. So if people type /banlist it will see the list of heads in the GUi. But when I type /ban it will add the target I ban into GUI
     
  11. Offline

    RcExtract

    You can request it in the plugin request form and I will make it for u.

    Basically you want to detect the command /ban executed, and add the target head into the GUI. Then, when command /banlist is executed, show a GUI and list all the banned player heads inside it.

    Something useful:

    1. You can handle PlayerCommandPreprocessEvent and get the player name by splitting the entire command input. Overriding the bukkit command /ban is a idea too.

    2. You can use non enhanced for loop to add all heads into a GUI and display it to the command sender.

    What's your problem? I cannot really help u without it.

    Edit: referring to your question detecting slot ? is occupied:

    You don't want to bind an item to a slot. If there is a new banned player, simply reload all the banned player heads into the GUI, instead of adding the new banned player head to the next available slot.
     
Thread Status:
Not open for further replies.

Share This Page