How to put players into a menu

Discussion in 'Plugin Development' started by DaanSander, Feb 26, 2015.

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

    DaanSander

    Hello i have a question have can i add player to a menu with their skulls
     
  2. Offline

    TGRHavoc

  3. Offline

    Ruptur

    @DaanSander

    TgrHavoc pretty much said everything you need to do in order to solve your problem yourself.

    But if you feel like you still dont understand or cant fix it, heres an experimental snippet of how
    to get what you want done.

    (only click this when you have attempted to solve it yourself ;)
    Show Spoiler

    Code:
            // create a null inven
            Inventory inv = Bukkit.createInventory(null, 16, "Players online!");
            // get all online players
            for(Player pp : Bukkit.getOnlinePlayers()){
                // creating a new itemstack for our head
                ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
    
                // new skullmeta for our headmeta (needs to be cast to skullmeta)
                SkullMeta im = (SkullMeta) head.getItemMeta();
    
                // This is where you assign what the head is going to look like
                im.setOwner(pp.getName());
    
                // set the name of the head
                im.setDisplayName(ChatColor.DARK_PURPLE + "" + ChatColor.GOLD + pp.getName());
    
                // set the lore of the head
                im.setLore(Arrays.asList("This is the head of " + p.getName()));
    
                // add the new item to the head
                head.setItemMeta(im);
    
                // add this new head to the inv we created
                inv.addItem(head);
    
    
            }
    
    // (Sorry for my weird variable names)
    
    All you need to do now is to show the player the inventory which can be easily done with

    Code:
    player.showInventory(x);
    // x being the name of the inventory
    // in this case you wanna show the inventory called 'inv'
    
     
  4. Offline

    1Rogue

    You shouldn't use the ordinal, that's a value from the implementation of enum itself, it has nothing to do with bukkit. Additionally .setOwner is a blocking method that you should run on a different thread.
     
  5. Offline

    Ruptur

    @1Rogue

    Thanks for the tip, sorry for lack on skull knowledge
    For future reference what do you advice i do - this was the way i learnt to do it
     
  6. Offline

    1Rogue

  7. Offline

    Ruptur

    @1Rogue

    '.setSkullType' is for skull objects
    In the example above i used an ItemStack and not a skull,
    so i cant set a skulltype on an itemstack
    Have you got any ideas about this can be solved - to set a itemmeta on an object it needs to be an ItemStack
     
  8. Offline

    DaanSander

    Well i managed to create a menu that add players heads when they join but how can i handle evnts with it so i can do like when i click on a player their head it would kick him?
     
  9. Offline

    ChipDev

    SkullMeta m = (SkullMeta) InventoryClickEvent.getItem().getItemMeta();
    if(m.??) {}
    Profit.
     
  10. Offline

    DaanSander

    @ChipDev this is what i tried but it doesnt seems to work

    code:
    Code:
     if (e.getCurrentItem().getItemMeta().getDisplayName().contains("§a§l")) {
                SkullMeta m = (SkullMeta) e.getCurrentItem().getItemMeta();
                p.kickPlayer(e.getCurrentItem().getItemMeta().getDisplayName());
                e.setCancelled(true);
            }
     
Thread Status:
Not open for further replies.

Share This Page