Player name -> UUID "Fetcher"

Discussion in 'Resources' started by evilmidget38, Mar 30, 2014.

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

    ZachBora

    It works but the UUID will be empty or null, at least if they never joined.

    evilmidget38 I have a question, if the mojang servers are down, what will your class do and what do you suggest I do on my plugin?
    Right now, I have an initial async task that updates the database and I will soon add an async task for when a command is used containing an offline player. But if the mojang servers are down, I guess I should somehow store that somewhere. Will probably use a new table for that.
     
  2. I already said:
    I tested it, it works if they've never joined. It says in the JavaDocs it will ALWAYS return something, never null. - It returns the correct UUID for players that are Minecraft users.

    Also, to answer your question even though it wasn't aimed at me, if mojang servers are down, it throws a errors. I have a fallback system so I try and catch the obtaining of UUIDs, if it failed, I use the getOfflinePlayer() system.
     
  3. Offline

    Kiskae

  4. Offline

    ZachBora

    With which build did you try? With 1.7.5 it didn't work, perhaps 1.7.8 does return the UUID.

    Which is faster, offlineplayer.uuid or evilmidget's class? Does offlineplayer raise an error if mojang server is down?

    What kind of system did you put in place when mojang servers are down? I was thinking of putting all my requests of uuid in a table and remove names from the table once I got their uuid.
     
  5. I built it against 1.7.8.

    getOfflinePlayer() is faster and does not raise an error if Mojang servers are down, and returns the correct UUID still (tested). Although, as I said before, Bukkit do not recommend using this system (deprecated) and say that it should be used just so that you can migrate from usernames to UUIDs.

    Although, you can use it in the production process in the future I believe, as they said:
    http://forums.bukkit.org/threads/psa-the-switch-to-uuids-potential-plugin-server-breakage.250915/

    Also, I put the getOfflinePlayer() system into place if the Mojang servers are down, storing all the player usernames and UUIDs into a config.

    Code:
    UUIDFetcher uuidFetcher = new UUIDFetcher(Arrays.asList("CyberTechGuy", "KingFaris10"));
    try {
        Map<String, UUID> playerUUIDs = uuidFetcher.call();
        this.getPlayersConfig().set(playerUUIDs.get("CyberTechGuy").toString(), "Default");
        this.getPlayersConfig().set(playerUUIDs.get("KingFaris10").toString(), "Default");
        this.savePlayersConfig();
    } catch (Exception ex) {
        ex.printStackTrace();
        this.getPlayersConfig().set(Bukkit.getOfflinePlayer("CyberTechGuy").getUniqueId().toString(), "Default");
        this.getPlayersConfig().set(Bukkit.getOfflinePlayer("KingFaris10").getUniqueId().toString(), "Default");
    }
    
     
  6. Offline

    ZachBora

    That makes no sense. How can the code know the uuid for a player that never logged on your server if the servers are down?
     
    Jozeth likes this.
  7. Offline

    blablubbabc

    I assume he probably got a correct uuid in his test because the uuid already was cached..
     
    Jozeth likes this.
  8. Oh, I did multiple tests and now I see that it freezes the main server thread until Mojang servers go back up. But the getOfflinePlayer() definitely DOES return the correct UUID even if the player's never joined the server before. I used random usernames of players that I know.
     
  9. Offline

    Double0negative

    Offline server by chance?
     
  10. Offline

    viper_monster

    Double0negative
     
  11. Nope, online mode.

    Okay, I created a clean fresh new server, made sure no worlds are created, etc. and just plugin JAR files.
    I made sure the server was on online-mode: true and then I made a small plugin like this:
    Code:
    public void onEnable() {
        System.out.println("KingFaris10's UUID: " + Bukkit.getOfflinePlayer("KingFaris10").getUniqueId().toString());
     
        this.getServer().getPluginManager().registerEvents(this, this);
    }
     
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        System.out.println("KingFaris10's join UUID: " + event.getPlayer().getUniqueId().toString());
    }
    
    I tested this, and both UUIDs matched each other, therefore meaning it does show even if the player hasn't joined the server before.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  12. Offline

    ZachBora

    From what I understand, getOfflinePlayer("KingFaris10") or .getUniqueId() will call the mojang server and will make the main thread wait while it gets the answer.
    That's why it's better to use evilmidget38 's code in an async thread over using getOfflinePlayer. I wouldn't use "getOfflinePlayer" when evilmidget's code does not work. I'd just try again later. Anything that freezes the main thread is bad.
     
  13. Yeah, I tested it and you're right, it does call the Mojang server and makes the main thread wait. Also, evilmidget's method throws errors if there's an error in the page.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  14. Offline

    ZachBora

    KingFaris11 Yeah, mojang made a new url to call and also limited something to 100 names per requests I think. Waiting on evilmidget38 's code to be updated.
     
    KingFaris11 likes this.
  15. Ohh! YAY! I think there's something like: api.mojang.com

    Saw it on Dinnerbone/Jeb's tweet.
     
  16. Offline

    evilmidget38

    KingFaris11 ZachBora

    I wrote a new version of UUIDFetcher last night when I heard the news, but I was tired so I didn't immediately post it. I was expecting them to maintain an API they published for longer, but I guess they've decided not to.

    Anyways, a new version of UUIDFetcher (v3) can be found here.

    The following features have been added:
    • Support for Mojang's new profiles API.
    • Utility methods for converting a UUID to bytes and back. This is useful if you want to store a UUID in a database in 16 bytes as opposed to storing it as either 36 or 32 bytes.
    • Rate limiting support, enabled by default. You can disable rate limiting by specifying 'false' in the constructor. This rate limiting is identical to what is currently in Minecraft, which is 100ms between each request. I encourage everyone to however keep rate limiting enabled as to not hit Mojang's severs excessively. They're being kind enough to provide an API, there's no need to abuse it.
    • Fun little method for retrieving the UUID of a single player. A few people have asked for this feature, so I went ahead and added it.
     
  17. Ily <3 No homo.

    Edit: Anything changed for NameFetcher?

    Edit 2: I don't see the point of getUUIDOf() as it would freeze the main thread if you keep calling it.
     
  18. Offline

    ZachBora

    evilmidget38 Merci beaucoup!
    Now I can continue world domi... I mean making PlotMe work for 1.8!
     
    Alshain01, Jozeth and KingFaris11 like this.
  19. Tu parles en Francais?

    Anyway, yeah, so erm NameFetcher won't work would it?
     
  20. Offline

    evilmidget38

    I changed NameFetcher a little bit last night to have better error messages if you provide an invalid UUID. There were no changes to the session servers, so the current version of NameFetcher will continue to work just fine. I'm still working on how exactly I want error handling to work in NameFetcher, so I'm holding off on releasing an update for it.
    Just like invoking call, it's a blocking method. If you need only a single name you can call that method in an asynchronous task as opposed to getting the map and retrieving their name from the map. It really isn't a significant addition or change, it's just a small thing that a few different people have asked for.
     
  21. Hey everyone, my friend (I think xD I met him last night on Skype - been talking for a long time) has an API for skins and UUIDs that has/will have a way better uptime than Mojang. It has a faster connection time too!

    http://mineskin.ca/
    To get UUID: http://mineskin.ca/uuid/?player=KingFaris10
    To get username: http://mineskin.ca/name/?uuid=f9843dd60a5f4009b451847291bda6b3

    ^ Example. Replace KingFaris10 with the player useername and the text after = with your UUID. Remember to use UUID.fromString() as the UUID returned doesn't have dashes.

    I hope you implement this as he said:
    I can't make this myself as I don't understand reading websites :/
     
    Jozeth likes this.
  22. Offline

    ZachBora

    KingFaris11 Might be "fast" but it's only 1 user at a time. With Mojang's we can send them a bunch of names at once.
     
  23. Offline

    Jozeth

    When you get the UUID from a player, it contains "-", I know you can remove them, but surely his fetcher should allow them?
     
  24. Mojang's has 100 per page or something. You could easily just loop through every person you need's page from that API (not Mojangs) and get it really quickly. Also, if you only want 10 people, it'd be quicker getting it from the website because for Mojang's, it'd download all 100 players then loop through all of them finding the correct player/

    Mojang don't use dashes, Bukkit do. His fetcher fetches from Mojang's "amazing" server, therefore returning what Mojang's fetcher would return. UUID.fromString() should fix that.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  25. Offline

    Jozeth

    So would it be better to store the UUIDs with dashes, as I already do for each player's file?
     
  26. Yes, dashes are read by Bukkit.

    Basically, the reason why you should migrate to my friend's API is that it has a fast load time, it can load 100 players fine and quickly with almost 100% uptime, whereas using Mojang servers means poor uptime and that it has to load 100players/page and read through each one, slowing down time. You wouldn't need EVERY player registered on Minecraft's UUID, so what's the point.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
    Jozeth likes this.
  27. Offline

    Jozeth

    Fair enough, but Mojang's server have quite good uptime, for how long they've been online for - http://xpaw.ru/mcstatus/
     
    KingFaris11 likes this.
  28. Offline

    ZachBora

    I have to oppose to that idea, more intermediate means it can break in more places. His website could go down for whatever reason. It could be Mojang down or his website.

    I know I keep saying Mojang server could go down, but I believe this api we're using will not go down as often as the login server.

    For all I know, his API could be using Mojang's API already. If it isn't, I might as well use what he's using instead of using his website.

    There is no reason to use his website. Faster? How? Does he CACHE the uuids? If he does, this is BAD. It means uuids and names will not be real-time accurate.
     
    Jozeth likes this.
  29. Not sure, I think he uses one of Mojang's servers that has almost 100% uptime for a month.
    [13:01:15] Yive // Tempest // Minebound: I use one of their servers which I know never goes down since I monitored it for like a month

    I'm getting:
    When using the latest UUIDFetcher.
    My code:
    Code:
    try {
        currentTime = System.currentTimeMillis();
        Map<String, UUID> playerMap = new UUIDFetcher(Arrays.asList("KingFaris10", "CyberTechGuy", "bass_flow", "YoloSwag69's")).call();
        System.out.println(playerMap);
        newTime = System.currentTimeMillis();
        System.out.println("Time taken using Mojang's API: " + (newTime - currentTime) + "ms");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    
    (Comparing a lot of players from my friend's API with Mojang's)

    Edit: Went on API website, said:
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  30. Offline

    ZachBora

    KingFaris11 I was getting that too, and seems one of the names I was sending was an empty string. This API doesn't like empty strings.

    I removed that and now it worked.

    Code:
    [19:01:10 INFO]: Checking if conversion to UUID needed...
    [19:01:10 INFO]: Verifying if database needs conversion
    [19:01:10 INFO]: Starting to convert plots to UUID
    [19:01:10 INFO]: Fetching 1445 UUIDs from Mojang servers...
    [19:01:13 INFO]: Finished fetching 1443 UUIDs. Starting database update.
    [19:01:20 INFO]: 1443 players converted
    [19:01:20 INFO]: Plot conversion finished
    
     
    KingFaris11 likes this.
Thread Status:
Not open for further replies.

Share This Page