Question about account UUID's

Discussion in 'Plugin Development' started by Debels, Feb 22, 2014.

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

    Debels

    How would I get a player/username based on a UUID?

    I know how to get the UUID based on the username, but not the other way around.

    Any Ideas?
     
  2. Offline

    SuperOmegaCow

    Debels with the player object you can use player.getUniqueId and to go from UUID to name use this library: here
     
  3. Offline

    noobkackboon

    AFAIK, bukkit will implement a LastKnownUsername store to go from UUID -> player.
    If you cannot wait, you can use https://sessionserver.mojang.com/session/minecraft/profile/{UUID}
    However, that is NOT good for bulk data and probably slow (depending on your internet speed).
    Be warned, I think mojang might block your IP if you go nuts on the link.
     
  4. Offline

    Alshain01

    Currently it doesn't exist in Bukkit, but internally Bukkit.getServer().getPlayer("name") is just a loop. You can do that yourself.

    Code:java
    1. Player getPlayer(UUID pID) {
    2. for(Player p : Bukkit.getServer().getOnlinePlayers()) {
    3. if(p.getUniqueId().equals(pID)) {
    4. return p;
    5. }
    6. }
    7. return null;
    8. }
     
  5. Offline

    noobkackboon

    That only works for online players though.
     
  6. Offline

    xize

    Debels
    you can use p.getUniqueId() for mojang UUIDs.
    first I thought it whas only the UUID of the world entity but it seems for players its actually the mojang UUID.
    now theres only one thing you should know when you go test it that is use online-mode true while debugging else it won't do anything or fails to work.

    some interesting classes:
    https://github.com/Bukkit/CraftBukk.../java/net/minecraft/server/LoginListener.java keep looking at the GameProfile.

    then this one: https://github.com/Bukkit/CraftBukk...in/java/net/minecraft/server/EntityHuman.java
    CraftPlayer extends EntityHuman so with other words I'm pretty sure UUID's work through getUniqueId() unless I overlooked something.

    I hope it helps a bit:)
     
    Garris0n likes this.
  7. Offline

    Alshain01

    EDIT: Mistaken.
     
  8. Offline

    Garris0n

    But getOfflinePlayers would return OfflinePlayers, which don't have getUniqueId...
     
  9. Offline

    Alshain01

    Ah, yeah your right. I didn't notice that. But was he asking for that anyway? He didn't actually ask for offline players in the OP.
     
  10. Offline

    Garris0n

    I don't know, I was just pointing out it wouldn't work.
     
  11. Offline

    SuperOmegaCow

  12. Offline

    Alshain01

    Lol, well I didn't. But it's not that old.
     
  13. Offline

    SuperOmegaCow

    Alshain01
    When it is 1/2 of a month it is old.
     
  14. Offline

    Alshain01

    Well look, if it appears at the top of my list and isn't tagged solved, I'm not going to check every little date code. I'm not the one that dug it out of it's grave.
     
  15. Offline

    codename_B

    Issues involving UUID are worth keeping open for discussion for the next few months anyway, a storm is coming.
     
    TheKomputerKing likes this.
  16. Offline

    xize

    the only way or atleast which I would do is creating my own custom instance wrapped around a configuration where the name of that file is actually the UUID, and inside this custom object I will do some checks on the constructor and change the name when necressay.

    then I make a Global HashMap such as HashMap<String, CustomObject> where the String the currently player name is and where the CustomObject instance is a wrapped interface, however to get a offline player I do something like this keep in mind what I told above:

    Code:
    public List<CustomOfflineObject> getOfflinePlayers() {
        File dir = new File(plugin.getDataFolder() + File.Seperator + "players");
        File[] list = dir.listFiles();
        List<CustomOfflineObject> list = new ArrayList<CustomObject>();
          for(File f : list) {
              FileConfiguration con = YamlConfiguration(f);
              CustomOfflineObject offlineplayer = new CustomOfflineObject(con.getString("username"));
              list.add(offlineplayer);
        }
        return list;
    }
     
    public CustomOfflineObject getOfflinePlayer(String p) {
            for(CustomOfflineObject obj : getOfflinePlayers()) {
                    if(obj.getUser().equalsIgnoreCase(p)) {
                        //it equals
                      return obj;
                    }
            }
        throw new NullPointerException("no player found by that name");
    }
    
    the code is bit messy though however thats the only long work around way how I could verify players, but I also see a long termed problematic effect what if you have around 100 unique players per day?, and then starts to for loop through all thus files I guess this would be shock for the cpu.

    I hope my text is clear got to many auto correction errors:(

    edit
    I don't like to addvertise my plugin project that much but I'm currently working out the same idea with my privated plugin and it works very good but I'm unsure how it would affect on bigger servers and if size of lines also mathers to.

    xEssentialsOfflinePlayer:
    https://github.com/xEssentials/xEss...sentials/memory/xEssentialsOfflinePlayer.java

    xEssentialsPlayer:
    https://github.com/xEssentials/xEss...ebox/essentials/memory/xEssentialsPlayer.java (gets instanced when the player joins, and cleared when they got kicked or quit)

    main class where getOfflinePlayer and a bunch of other verify methods are:
    https://github.com/xEssentials/xEss...c/tv/mineinthebox/essentials/xEssentials.java
     
Thread Status:
Not open for further replies.

Share This Page