Small UUID library

Discussion in 'Resources' started by CraftThatBlock, Mar 9, 2014.

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


    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
    To get UUID: simple use this format: (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:
    1. public static String getUUID(String player) {
    2. String uuid = null;
    3. try {
    4. // Get the UUID from SwordPVP
    5. URL url = new URL("[url][/url]" + player);
    6. URLConnection uc = url.openConnection();
    7. uc.setUseCaches(false);
    8. uc.setDefaultUseCaches(false);
    9. uc.addRequestProperty("User-Agent", "Mozilla/5.0");
    10. uc.addRequestProperty("Cache-Control", "no-cache, no-store, must-revalidate");
    11. uc.addRequestProperty("Pragma", "no-cache");
    13. // Parse it
    14. String json = new Scanner(uc.getInputStream(), "UTF-8").useDelimiter("\\A").next();
    15. JSONParser parser = new JSONParser();
    16. Object obj = parser.parse(json);
    17. uuid = (String) ((JSONObject) ((JSONArray) ((JSONObject) obj).get("profiles")).get(0)).get("id");
    18. } catch (Exception ex) {
    19. ex.printStackTrace();
    20. }
    21. return uuid;
    22. }

    Then you can use getUUID(username) to get a string version of the UUID.
    PHP and other languages are on the Github.


  2. Offline


    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.

    1. RequestFactory requestFactory = new RequestFactory("[url][/url]");
    2. requestFactory.setPost(true);
    3. requestFactory.setJsonPost("[{\"name\":\"ECB2\", \"agent\":\"Minecraft\"}]");
    4. JsonObject json = JsonObject.readFrom(;
    5. JsonObject profiles = json.get("profiles").asArray().get(0).asObject();
    6. System.out.println("UUID: " + profiles.get("id").asString());
    Milkywayz likes this.
  3. Offline


    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!
  4. Offline


    DarkBladee12 iirc bukkits method generates the entity UUID, not the players UUID.
  5. Offline


    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.
  6. Offline


    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?
  7. Offline


    Within Bukkit, no.
  8. Offline


    turt2live will such a method be added to Bukkit once Mojang's system has fully changed to UUID and allows name changing?
  9. Offline


    No idea.
  10. Offline


    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 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.
  11. Offline


    CraftThatBlock well but it would be more useful to create something that gets the current name from an UUID.
  12. Offline


    That would be epic... but Mojang doesn't provide that yet (afaik).
  13. Offline


    CraftThatBlock I hope either Mojang or Bukkit provides a way to to that in the future!
  14. Offline


    I hope they do. :)
  15. Offline


    Last edited by a moderator: Jun 7, 2016
  16. Offline


    Maybe you want to try this. (Look at the last paragraph of the post.)
    DarkBladee12 likes this.
  17. Offline


    CraftThatBlock Doing this:

    $sUUID getUUID("DevRo_");
    Outputs nothing for some reason.
Thread Status:
Not open for further replies.

Share This Page