Get UUID from AccountsClient

Discussion in 'Plugin Development' started by x128, Mar 28, 2014.

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

    x128

    Mojang is pushing all servers to start storing data as UUIDs, as most of you know. They also have their API at the following website:
    https://github.com/Mojang/AccountsClient/
    I've been developing plugins and other things for quite a while but I can not figure out how to use this code in my project. I am making a private API to make dealing with UUIDs easier but I need to be able to fetch the UUID of offline players.
    If anyone can quickly explain how to add this to my eclipse project or point me in the right direction I would greatly appreciate it.
     
  2. Offline

    AoH_Ruthless

    x128
    When building with Bukkit or CB, using the method Player.getUniqueID() returns their UUID.
     
  3. Offline

    x128

    AoH_Ruthless I already know that but I need to bulk migrate a whole list of Minecraft usernames (thousands) to UUIDs and waiting for each of them to login so I can run p.getUniqueID() is not a viable solution.
    Thanks for your suggestion but I need to access Mojang's api :)
     
  4. Offline

    SuperOmegaCow

    x128
    Something like this:
    Code:java
    1. final HttpProfileRepository repository = new HttpProfileRepository();
    2. public String getUUID(String name) {
    3. Profile[] profiles = repository.findProfilesByCriteria(new ProfileCriteria[] { new ProfileCriteria(name, "minecraft") });
    4. if (profiles.length == 1)
    5. return profiles[0].getId();
    6. else {
    7. return "";
    8. }

    Note: this doesn't return UUID format, it returns a uuid with no - in it. To check this against a player's uuid with the bukkit api simply do
    Code:java
    1. Bukkit.getPlayer("SuperOmegaCow").getUniqueId().toString().replace("-", "").equals(getUUID("SuperOmegaCow"))
     
  5. Offline

    x128

    SuperOmegaCow Thank you for that code.
    In order to execute the code, I need to add the Mojang API from GitHub to my eclipse project. I am still lost on how to do that.
    Thank you for your help! I really appreciate it.
     
  6. Offline

    RawCode

    adding code to project is generic java skill, you shoud learn java before going to use bukkit api
     
  7. Offline

    x128

    RawCode I know that, I've never gotten code from github before. I expected it to be much harder than it was, but it was fairly straight forward.
    Thanks for your help everyone!
     
  8. Offline

    RawCode

  9. Offline

    x128

    Ran into another problem. Since a function must be static to be called from another plugin, and more importantly to be used as an api, I am unable to get my data file to store the UUID once fetching it from Mojang, and creating a new instance errors on command.
     
  10. Offline

    RainoBoy97

    x128
    You cannot initialize your main class, remove line 65.
     
  11. Offline

    SuperOmegaCow

    x128
    You can't create a second instance of the main class that extends JavaPlugin.
     
  12. Offline

    CubieX

    Also be aware that this method which gets the UUID from Mojang will lag your server hard if you do it synchronously.
    So use an async task to do the request to prevent that.
     
Thread Status:
Not open for further replies.

Share This Page