Solved Getting a UUID from a username

Discussion in 'Plugin Development' started by pookeythekid, Aug 2, 2014.

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

    pookeythekid

    Since I couldn't find one via Bukkit Java Docs, I was wondering if there is a method that I could use to fetch a player's UUID by using their username as an argument. For example: SomeUUIDClass.getUUID(playerName);

    I'd like to stay away from using getPlayer(string) then player.getUniqueID(), since the whole reason I want to get the UUID is to not use a deprecated method.

    Thanks in advance.
     
  2. Offline

    Gamecube762

    pookeythekid No need to be afraid of getPlayer(string) being deprecated, its only like that to alert plugin devs about the change to the UUID system. In 1.8, Bukkit will remove the deprecation on getPlayer(string).
     
    Giraffeknee likes this.
  3. Offline

    pookeythekid

    Gamecube762 But with 1.8 comes username changing, doesn't it? Isn't that a big problem with getPlayer(string)?
     
  4. Offline

    CeramicTitan

    evilmidget38 has a couple of classes that handles these very well;

    UUIDFetcher - "...for retrieving the UUID of a player given their userame"

    NameFetcher - "...for retrieving the username of a player given their UUID"
     
  5. Offline

    Gater12

    pookeythekid
    Use getPlayer(String s) for session. Use UUID if you want to store persistent data to the player (names are no longer unique).
     
    Gamecube762 likes this.
  6. Offline

    pookeythekid

  7. Offline

    JustinsCool15

    pookeythekid

    Code:java
    1. Bukkit.getServer().getPlayer(player.getName()).getUniqueId();


    or this if you have the player already.

    Code:java
    1. player.getUniqueID();
     
  8. That makes no sense, why would use use getPlayer() and input the player object's getName() String, just use player.getUniqueId().
     
  9. Offline

    pookeythekid

    KingFaris11 xD Yeah, quite redundant.

    JustinsCool15 I said that I wanted to stay away from using getPlayer(string) because in 1.8 player names will no longer be unique.
     
    KingFaris11 likes this.
  10. Offline

    JustinsCool15

    pookeythekid But the name will be unique while they're on the server. It won't change while they're on your server. Right?
     
  11. Offline

    pookeythekid

    JustinsCool15 I don't know, but I'm taking the safe path.

    Wait a minute... Wouldn't even getting the UUID of a player's username be worthless with 1.8 name changing? I'd think it's as good as getting an OfflinePlayer by using their username.

    Edit: Or will players have to change their name to a username that hasn't already been taken?

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

    CeramicTitan

    That is why I linked you to those two resources. They connect to the Minecraft Servers, where thy interact with the data.
     
  13. Offline

    xTigerRebornx

    pookeythekid A situation where name -> UUID would be useful: Say you have an economy that stores based on UUID, the admin wants to give PlayerA money. Rather then the Admin having to get the player's UUID, you simply fetch it (though, locally storing would be better on Mojang servers)
     
  14. Offline

    pookeythekid

    xTigerRebornx Haha, funny you say that. I am making an economy plugin that stores by UUIDs. And yes, I do locally store the UUIDs.

    CeramicTitan Ohh I get it. Alright, thanks.

    Edit: Wait no, I still have a question: If usernames are no longer unique, that means there can be duplicates (go figure). So if you search "pookeythekid" (that's also my MC username) in the Minecraft servers, you may be presented with two pookeythekids. That would mean you could get the wrong UUID, wouldn't it?
     
  15. Offline

    CeramicTitan

    You are going to have the same UUID regardless of what you change your name to. Also if a name is taken, you probably wont be allowed to take it.
     
  16. Offline

    pookeythekid

    CeramicTitan Ah, so there still won't be duplicates. That makes sense now. So, is getPlayer(username) going to become obsolete because it may lead to plugins treating the same players like newbies?
     
  17. Offline

    CeramicTitan

    What? If Player A joins the server and he is op. If they change their name and join the server, depending how you go about it, they should still be op when the join the server. I don't really see how it will impact.
     
  18. Offline

    pookeythekid

    CeramicTitan Never mind, I'll save confusion and leave it at "there won't be duplicates". That's all I needed to know.
     
  19. Offline

    eriosgamer

    i use this way, maybe is what you are looking for

    Code:java
    1.  
    2. String playername = "eriosgamer"; //Here you can receive the name from a command with something like args[0]
    3. OfflinePlayer offPlayer= Bukkit.getServer().getOfflinePlayer(playername);
    4. UUID id = offPlayer.getUniqueId();
    5. String uuid = offPlayer.getUniqueId().toString();
    6.  
     
  20. Offline

    fireblast709

    There is still a major use case for Bukkit.getPlayer(String), namely user friendly commands.
     
  21. Offline

    pookeythekid

    fireblast709 Mm. Good point.

    eriosgamer I suppose that'd work, but then it's exactly what I was trying to find an alternative for. It wouldn't work out best with the context in which I'm using it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page