Solved Help in Getting a Selected Player by selecting is head GUI

Discussion in 'Spigot Plugin Development' started by RoboBoy99, Feb 5, 2020.

  1. I have made a Gui with players head and their skins And I want to target a certain player when I click is head
    I have this code but it takes a lot of times to get the selected target (I also tried to do getPlayer, And I get the same results)

    Code (Text):
    ClickEvent:
               if(e.getCurrentItem().getType() == Material.PLAYER_HEAD)
                {
                    @SuppressWarnings("deprecation")
                    OfflinePlayer WhoOptions = plugin.getServer().getOfflinePlayer(e.getCurrentItem().getItemMeta().getDisplayName());
                    ClanMenu.PlayerOption(player, WhoOptions);
                }
                e.setCancelled(true);


    GUI:

        public static void PlayerOption(Player player, OfflinePlayer target)
        {
            Inventory PO = Bukkit.createInventory(player, 9 , ChatColor.BOLD + "" + ChatColor.GREEN + "What to do with " + target.getName() + ChatColor.GREEN +"?");
            player.openInventory(PO);
        }
     
    #1 RoboBoy99, Feb 5, 2020
    Last edited: Feb 5, 2020
  2. You have made several posts now, where people have asked you to wrap your code in a "code" tag, and you haven't done it...
     
    • Agree Agree x 1
  3. @Vibemaster How will I do that? and no one ever asked me to warp my code until now so don't make up stuff
     
  4. thx but can someone help me with my issue?
     
    #5 RoboBoy99, Feb 5, 2020
    Last edited: Feb 5, 2020
  5. drives_a_ford

    Moderator

    If your server is quite old and you have thousands of players, using the player's name to find them can take a long time.
    Just take a look at the comment in the source.

    You want to look for players using their UUIDs. Not only does it save on time (a lot!), players can also change their names, but their UUID stays the same.
     
  6. @drives_a_ford Is there a way I can use that for the ClickEvent? and if there is so how?
     
  7. drives_a_ford

    Moderator

  8. yes, the skull is of a player but how will I get it in the clickEvent? because I'm getting the skull in a different class
     
  9. drives_a_ford

    Moderator

    You're getting the skull with e.getCurrentItem(). Just use the instance.
     
  10. @drives_a_ford I'm trying to figure this part-out a
    Code (Text):
    OfflinePlayer WhoOptions = Bukkit.getServer().getOfflinePlayer(e.getCurrentItem().getItemMeta().getDisplayName());
     
  11. drives_a_ford

    Moderator

    To recap again:
     
  12. You need to get the ItemMeta and then cast it to a SkullMeta, then you can use SkullMeta#getOwningPlayer to retrieve an OfflinePlayer object from the meta
     
  13. I still don't understand how to use it in the ClickEvent method
     
  14. drives_a_ford

    Moderator

    What is it that's confusing you exactly?

    I've told you exactly which methods to use and in which order. All you need to do is use them.
    If you don't know what casting is, google it. If you don't know what a method is, google it.

    If you're expecting to be spoonfed code, this won't happen.

    Which is exactly what I said.
     
  15. I was going to spoonfeed him meh.
    Yeah when I replied your post wasn't appearing yet for me
     
  16. Thx for everyone help it's working now
     
    • Like Like x 1