Hey guys, CraftThatBlock here. I made a very small Minecraft username to UUID library (in PHP) with examples in Java and PHP (pull requests welcomed). The actual library is hosted on https://uuid.swordpvp.com/. To get UUID: simple use this format: https://uuid.swordpvp.com/uuid/CraftThatB (CraftThatB being the username getting the UUID from) This gets directly from Mojang's server, but it is easier to use as Mojang's uses a post request and a bunch of other complicated things, and do not provide examples. To use it in Java, simple use this: Code:java public static String getUUID(String player) { String uuid = null; try { // Get the UUID from SwordPVP URL url = new URL("[url]https://uuid.swordpvp.com/uuid/[/url]" + player); URLConnection uc = url.openConnection(); uc.setUseCaches(false); uc.setDefaultUseCaches(false); uc.addRequestProperty("User-Agent", "Mozilla/5.0"); uc.addRequestProperty("Cache-Control", "no-cache, no-store, must-revalidate"); uc.addRequestProperty("Pragma", "no-cache"); // Parse it String json = new Scanner(uc.getInputStream(), "UTF-8").useDelimiter("\\A").next(); JSONParser parser = new JSONParser(); Object obj = parser.parse(json); uuid = (String) ((JSONObject) ((JSONArray) ((JSONObject) obj).get("profiles")).get(0)).get("id"); } catch (Exception ex) { ex.printStackTrace(); } return uuid; } Then you can use getUUID(username) to get a string version of the UUID. PHP and other languages are on the Github. Github Thanks!
Why are you using such a big framework for a simple task like that? Also it's easier and safer to grab it yourself, since you won't have to rely on someones service. Example: Code:java RequestFactory requestFactory = new RequestFactory("[url]https://api.mojang.com/profiles/page/1[/url]"); requestFactory.setPost(true); requestFactory.setJsonPost("[{\"name\":\"ECB2\", \"agent\":\"Minecraft\"}]"); JsonObject json = JsonObject.readFrom(requestFactory.run()); JsonObject profiles = json.get("profiles").asArray().get(0).asObject(); System.out.println("UUID: " + profiles.get("id").asString());
CraftThatBlock ECB2 Why so complicated when you can just use PLAYER.getUniqueId()? I've tested this and the method of this thread and they both return me the same as seen in this picture (upper is with the method of the thread and lower with the Bukkit method): The only downside of this is that OfflinePlayer doesn't have such a method, but I assume Bukkit will also add this method to this class when Mojang's system changes fully to UUID!
False. Bukkit retrieves the UUID from the NMS code, which uses the entity UUID (correct), but for players NMS will use the player's UUID (provided you are on an online mode server). Offline mode servers are unsupported by this functionality. So Bukkit just ports the call to NMS for getting the UUID.
turt2live is there currently a way to retrieve the name from an UUID when the player is offline or do you have to make yourself a database where you store the name that is bound to the UUID?
turt2live will such a method be added to Bukkit once Mojang's system has fully changed to UUID and allows name changing?
My library simply gets it from Mojang, but in a simpler form factor. Making a post to api.mojang and stuff sometimes can be a bit hard, but uuid.swordpvp.com/uuid/Player is much simpler. This was meant to make it so even offline servers (using BungeeCord) works, or basically ANY Java application, or PHP, as in the examples. This was not meant to replace player.getUUID() nor Mojang's API, as it uses Mojang's API. This was simply made to make it easier.
CraftThatBlock well but it would be more useful to create something that gets the current name from an UUID.
Added reverse lookup (UUID -> Name): https://github.com/SwordPVP/MinecraftUUID Example: http://uuid.swordpvp.com/session/511ec68267ac4750abb80afb170d21d5 I found a way and added it into my library! See the post above EDIT by Moderator: merged posts, please use the edit button instead of double posting.
CraftThatBlock Doing this: PHP: require('./includes/config.php'); $sUUID = getUUID("DevRo_"); echo $sUUID; Outputs nothing for some reason.