Solved UUID of Offline Players

Discussion in 'Plugin Help/Development/Requests' started by Robin Bi, Mar 31, 2015.

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

    Robin Bi

    So I'm sure this question has been asked like a thousand times. But I wasn't able to find a good answer to it.


    I'm currently working on a plugin that converts saves of an old plugin (not coded by me) to a new format (coded by me). The old plugin saved files in the format "playername.properties" and since UUIDs have been introduced, I'll need "uuid.properties". I'd like to be able to convert all files at once without having people playing on the server, because the plugin might break when theres 50% UUID and 50% Playername.

    So I need to get the UUIDs of offline players without having any information about them but the name I've seen them the last time with.
    I've read threads like "Getting Offline Player UUID" on the spigot forums, but they link to libraries and threads that are not accessable anymore.

    I know sites where I enter the player's current name and it outputs me the UUID, so it should be possible to access that through my plugin, right? And since I'm hopefully not the only one with this need, there should already be a UUID Fetching class that works with offline players, huh?


    I'd really appreciate some hints.
     
  2. Offline

    1Rogue Retired Staff

    Code:java
    1. OfflinePlayer op = Bukkit.getOfflinePlayer(/* your name to lookup*/);
    2. if (op.hasPlayedBefore()) {
    3. UUID uuid = op.getUniqueId();
    4. } else {
    5. //hasn't played before
    6. }
     
  3. Offline

    TehHypnoz

    You can use the Mojang API for this:

    https://api.mojang.com/users/profiles/minecraft/<Username>

    Note: the username isn't case sensitive.

    Also, this is really important, do NOT try to use it in the main thread because that will freeze the entire server until the information is retrieved.

    EDIT: You can also get an offlineplayer's UUID if they have joined before, like in the example of @1Rogue
     
  4. Offline

    Robin Bi

    @1Rogue Thanks, but I'm afraid there's no such method getUniqueId() for the variable type OfflinePlayer. I've tried it with the following code instead:

    Code:
    else if (cmd.getName().equalsIgnoreCase("uuid")) {
        String target = args[0];
        OfflinePlayer op = Bukkit.getOfflinePlayer(target);
        if (op.hasPlayedBefore()) {
            UUID uuid = op.getPlayer().getUniqueId();
            sender.sendMessage(uuid.toString());
        }
    }

    But this throws a NPE even though the player I've asked for has played before for sure. Is that what you meant? Because op.getUniqueId() does not exist... :confused:



    @TehHypnoz Yeah, I know those sites, but I have never worked with plugins that get information out of the internet (of course i've worked with MySQL, but you know, that's something else...) so I'm looking for an easier way.
     
  5. Offline

    1Rogue Retired Staff

    I can guarantee you there is an OfflinePlayer#getUniqueId() method: http://docs.codelanx.com/Bukkit/1.8/org/bukkit/OfflinePlayer.html#getUniqueId--

    Additionally, op.getPlayer() only returns a Player if they are online.
     
  6. Offline

    Robin Bi

    @1Rogue Sorry, can't find it...
    [​IMG]


    EDIT: FYI, the cast is a (Object) cast, that can't be the solution.

    EDIT again: Maybe I use a different craftbukkit library version??
     
  7. Offline

    1Rogue Retired Staff

    What bukkit version are you using (and why are you using craftbukkit...?)
     
  8. Offline

    Robin Bi

    @1Rogue Whoops, I'm using the Bukkit API from a long time ago... March 2014 in fact. I'm using Spigot on my server though. Am I wrong or is the library unavailable since the DMCA-trouble?
     
  9. Offline

    bwfcwalshy Retired Staff

    Moved to Bukkit Alternates.
     
Thread Status:
Not open for further replies.

Share This Page