Solved Getting the player

Discussion in 'Plugin Development' started by bubblefat_, Jun 17, 2015.

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

    bubblefat_

    I'm making a plugin where you can type a command and it opens an inventory with every players name on a skull. When you click the skull I need to know how to get the name of the player.

    Heres my call that needs to get the player from.

    Code:
        @EventHandler
        public void onClick(InventoryClickEvent event) {
            HumanEntity entity = event.getWhoClicked();
            if ((entity instanceof Player)){
                Player player = (Player)entity;
                ItemStack clicked = event.getCurrentItem();
               
                if(event.getInventory().getName().equals(StarInventory.getStarInventory(player).getName())){
                if(clicked !=null){
               
                    if(clicked.getType() == Material.SKULL_ITEM) {
                       
                    }
               
                }
                }   
                }
        }
     
  2. Offline

    ESSHD

    You need to check what the name of the skull is, then you can check if that player is online or offline by doing
    Code:
    Player player = Bukkit.getPlayer(skull name);
    if (player == null) {
    //player is offline
    }
    //player is online
     
  3. Offline

    bubblefat_

    @ESSHD
    What I have tried is

    Code:
                    if(clicked.getType() == Material.SKULL_ITEM) {
                        SkullMeta item = (SkullMeta)clicked.getItemMeta();
                        Player target = Bukkit.getServer().getPlayer(item.getDisplayName());
                       
                        player.sendMessage("Click Test");
                       
                        if(target !=null){
                        target.sendMessage("Testing");
                        }
                    }
    and

    Code:
                    if(clicked.getType() == Material.SKULL_ITEM) {
                        ItemMeta item = (ItemMeta)clicked.getItemMeta();
                        Player target = Bukkit.getServer().getPlayer(item.getDisplayName());
                       
                        player.sendMessage("Click Test");
                       
                        if(target !=null){
                        target.sendMessage("Testing");
                        }
                    }
    And still didn't work :/
     
  4. Offline

    dlange

    @bubblefat_ When you say it doesn't work you mean...? What isn't working?
     
  5. Offline

    87pen

    If you are looking to have an inventory where each player that's online has their head in an inventory. I would loop through all online players and for every online player create the head, set them as owner and place it in the inventory. If they are offline remove it if it's there.

    Setting the owner of a skull.
    Code:
            ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
            SkullMeta getMeta = (SkullMeta)skull.getItemMeta();
            getMeta.setOwner(p.getName());
            skull.setItemMeta(getMeta);
    
     
    bubblefat_ likes this.
Thread Status:
Not open for further replies.

Share This Page