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); }
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...
@Vibemaster How will I do that? and no one ever asked me to warp my code until now so don't make up stuff
https://www.spigotmc.org/threads/he...t-from-a-certain-hashmap.415489/#post-3676037 Right there someone did, when you make a post there is a little + icon on the text toolbar. Click that and then code and you will be able to paste in your code.
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.
If the skull is of a player's then, you get its meta with ItemStack#getItemMeta and then cast and use SkullMeta#getOwningPlayer.
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
@drives_a_ford I'm trying to figure this part-out a Code (Text): OfflinePlayer WhoOptions = Bukkit.getServer().getOfflinePlayer(e.getCurrentItem().getItemMeta().getDisplayName());
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
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.