So I am developing a resourceful plugin that gets the players UUID and tells the sender. But how would I use the getUniqueID()? Would I make a thing like: Bukkit.getServer().getPlayer(args[0]).getUniqueID(); Then how would I send the message to the sender? Would I make it using a string or would I use a final?
Code:java sender.sendMessage(ChatColor.GREEN + Bukkit.getServer().getPlayer(args[0]).getUniqueID(););
I believe something like: Code: @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (cmd.getName().equalsIgnoreCase("uuid")) { sender.sendMessage(args[0] + "'s UUID: " + Bukkit.getServer().getPlayer(args[0]).getUniqueID()); return true; } return false; }
football70500 you have duplicate ; there, and you are trying to add ChatColor to UUID. Starfire1337 missing args.length check and and you are also trying to get a UUID of a string.
getUniqueID() only works for players that have played on your server before. If your wanting UUID of player that has never played on your server before, you should look into UUID Fetcher If the players you will be looking up have played on your server before then simply do. Code:java if(getServer().getPlayer(args[0]) != null){ //Make sure the player is online before creating player object. Player thePlayer = getServer().getPlayer(args[0]); //Player object.String playerUUID = thePlayer.getUniqueId().toString(); //Convert the UUID to string so you can send it to the sender. sender.sendMessage("Player name: " + thePlayer.getName() + "\nPlayer UUID: " + playerUUID); }