UUID Questions

Discussion in 'Plugin Development' started by Niknea, Apr 5, 2014.

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

    Niknea

    Hey guys, I have a few questions about UUID that will be added in 1.8.

    1. Firstly do I use p.getName(); or p.getDisplayName();?

    2. How can I get a player from there UUID? Ex. get the player from the UUID and give them one coal.

    3. When should I get them from there UUID and when should I get them from there p.getName(); or p.getDisplayName();?

    4. How do I store the players UUID? Not there in game name.

    5. Does anyone have any good guides / videos to understand this a bit more?

    Thanks,
    Niknea
     
  2. Offline

    iiHeroo

    I'd go with p.getDisplayName() since it'll return your name (that I know of currently), and nicknames don't override this since you need to set it upon chat event.
     
  3. Offline

    Wolfey

    1. You don't use either. You use the player's UUID.
    2. Bukkit.getPlayer(uuid);
    3. I don't understand this question.
    4. If you want to save it in a config, save it as a string, (uuid.toString())
    5. Pogostick29's video:
     
  4. Offline

    Niknea

    Wolfey So I should never use p.getName(); or p.getDisplayName(); ever again?
     
  5. Offline

    Wolfey

    Niknea No... is that what you were asking?
     
  6. Offline

    xTigerRebornx

    Niknea It depends on the situation. If you have something like a Block Logger or Economy, you'd need to store it VIA UUID, but if you had something that didn't require persistance, like a teleporter or a command to list online players (something that will only apply while that Player is still online), you'd have to determine if you actually needed to use UUID
     
  7. Offline

    Shevchik

    Wrong.
    Using names are still preferred when you are storing temporaly data for example list of players in minigame.
     
  8. Offline

    iiHeroo


    You know you can use getDisplayName to return the name and not the UUID?
     
  9. Offline

    Wolfey

    Shevchik Sure... But what I do is I store the player's uuid, then I get the player from the uuid.
     
  10. Offline

    amhokies

    There's really no reason to do this if you're not storing the data to disk.
     
  11. Offline

    Wolfey

    amhokies It's how I do it, it's how I recommend.

    You don't have to do it the way I do, though.
     
  12. Offline

    amhokies

    But you literally just told someone that storing the player's name temporarily is the wrong way to do it.
     
  13. Offline

    Wolfey

    amhokies What I meant to say was...
     
  14. If you don't need the name, then UUID is certainly "better", also for future purposes. If your store data until logout only, it just does not matter. It could matter if you want to use that data to do something else that needs the UUID, but that would fall under "need UUID" then. I am sure that Bukkit will add all the lookup methods for online players, with offline players it'll better by asynchronous lookups for getting the name (or UUID, though that way round probably should be done before 1.8).

    Using display names to store stuff does not seem a good thing for identifying players, display names are not even forced to be unique, and get changed by a couple of plugins - one could reason that people want to address a player by display name, however that's even more confusing if not all plugins support that - so unless all of your plugins are made to support display names or multiple approaches, i would just use the real name rather. Player.getName() should get the unique name that is set at the moment, and it won't be inefficient and it won't be changing while online).
     
  15. Offline

    BillyGalbreath

    player.getName() is for retrieving the unique player name. player.getDisplayName() is for getting the non unique player display name (often called nickname). The two are very different, and for identifying a player do NOT use the display name. Neither are sufficient for storing data. Right now using the real names are the fastest method, but in the future the UUIDs will be the fastest.

    As mentioned before, Bukkit.getPlayer(UUID);

    Use UUID for storing data. Use the names for display purposes ONLY.

    As mentioned before, UUID.toString();

    You arent going to learn much from a video other than how to copy someone else. Read read read read read. And then read some more.
    The Bukkit PSA
    Google.com
     
  16. Offline

    Mr360zack

    From what I understand, using Bukkit.getPlayer(UUID) is slow, right? If so, what id do, make a file called uuids or whatever, and when a player joins set the UUID to their name, ex yourConfig.set(p.getName(), p.getUniqueId());

    Correct me if I'm wrong, this all confuses my mind and I hate Mojang for doing this :(
     
  17. Offline

    BillyGalbreath

    Its only slow right now. Bukkit is working hard on the entire UUID system right now, and very soon (couple of months maybe) it will actually be the fastest way of doing this stuff.
     
  18. Offline

    Mr360zack

    Ok... I thought it would always be slow because it has to make a request from the Mojang servers or something
     
  19. Offline

    FlareLine

    I'm pretty sure the Player's UUID is stored within the server as soon as they join.
    i.e.
    Code:
    [11:59:16] [User Authenticator #1/INFO]: UUID of player FlareLine is 6c7ec3d9036c45269de918497bb28095
    [11:59:16] [Server thread/INFO]: Loaded player file for FlareLine
    [11:59:16] [Server thread/INFO]: FlareLine[/127.0.0.1:6644] logged in with entity id 549 at ([Spawn] 76.52819139344871, 12.90382143613951, 606.8030465394085)
     
  20. Offline

    Mr360zack

    Well, that looks new. Still, how could we access that information? Is there already a method for it? Sorry, I'm on vacation without computer access, haven't had a chance to play around with this yet.
     
  21. Offline

    BillyGalbreath

    player.getUniqueId();
     
  22. Offline

    FlareLine

    Mr360zack
    I'm pretty sure this returns the value stored within Bukkit.

    I'm also running on quite a recent snapshot, so maybe it was added not long ago.
     
  23. Offline

    Mr360zack

    If the player is offline, can you still do this?
     
  24. Offline

    FlareLine

    Mr360zack Let me get back to you on that.

    No it won't work as the player variable will equate to null.
     
  25. Offline

    Mr360zack

    So it might be a good idea to store their UUID lol
     
  26. Offline

    FlareLine

  27. Offline

    BillyGalbreath

    Its something Bukkit is still in the works on, but this (AFAIK) will be the method used to obtain the UUID. I believe the UUID will be updated when a player connects (if not already doing so) and the UUID will be able to be used when the player leaves too (currently not working like this for now).
     
  28. Offline

    FlareLine

    BillyGalbreath This must be flatfile storage if the UUIDs don't rollover (/reload)s
     
  29. Offline

    Mr360zack

    Ok, thanks guys! I have a lot of work to do when I get home... I have this huge plugin with like 50 classes...

    FlareLine thanks for the help

    Edit: FlareLine yes I know lol I'm not a java newbie, just don't know any of this new UUID stuff as a I am on vacation.
     
  30. Offline

    Niknea

    Wolfey amhokies asofold BillyGalbreath So will this code work? I'm trying to check if they have the permission node, even if they changed there username, they will still have the perm.

    PHP:
    @EventHandler
    public void onJoin(PlayerJoinEvent e){
     
    Player p e.getPlayer();
    UUID uuid p.getUniqueID(); <-- Would this workO.o
     
    if(uuid.hasPermission("test.test")){
    p.sendMessage("It works!");
    }
    }
     
Thread Status:
Not open for further replies.

Share This Page