Pull a UUID From Config?

Discussion in 'Spigot Plugin Development' started by ShishKaBobz, Apr 22, 2017.

  1. Hello! I was just wondering how i can pull a UUID (Thats a string) from the config? I got this code from the Bukkit Wiki idk if it works yet but i think it will fit my needs :D

    Code (Text):
    List<String> listOfStrings = Arrays.asList("Hello World", "Welcome to Bukkit", "Have a Good Day!");
    this.getConfig().set("path.to.list", listOfStrings);
    Thanks in advance! This has been driving me crazy!!!
     
  2. Once you have a String, you can call UUID.fromString, this will either return the UUID or it will throw an exception if the string doesnt represent a UUID
     
  3. Ty but if i do UUID.fromString(p.getUniqueId()) it doesnt work how can i fix this :D Again ty so much
     
  4. Deconstruct what you're doing. Player#getUniqueId returns a UUID, UUID.fromString takes in a String. A UUID isn't a String.
    This call to fromString is redundant, as getUniqueId already returns a UUID
     
  5. Save a UUID: FileConfiguration#set(String, UUID#toString)
    Load a UUID: UUID.fromString(FileConfiguration#getString(String))
     
    • Agree Agree x 1
  6. Would this work??
    if(UUID.fromString(p.getUniqueId().toString()) != null){
    p.setDisplayName("§b§lBEAST " + nick);
    }
     
  7. ... Why would you need to take a player's uuid and turn it into a string then turn it back into a uuid to check if it's null? It's not even possible for that to be null.
     
    • Like Like x 1
  8. How should i do it then?? Im confused i was just doing what it told me to do
     
  9. x y... lol
     
    • Funny Funny x 1
  10. What exactly are you trying to accomplish?
     
  11. And if i use UUID.fromString(FileConfiguration#getString(String)) my string would be player.getUUID or whatever
     
  12. Try to get a UUID from a config
     
  13. Before you get a UUID from config, you need to save it in the config. And then, you need to do UUID.fromString(config.getString("uuid")) to get the UUID back. But if you just need to check if it's null, don't bother turning it into a UUID. Just do
    if (!config.contains("uuid")) {

    }
     
  14. But my string is my UUID, I have the UUID then a Nickname as the Value
     
  15. maldahleh

    Wiki Team

    You aren't clear at all on what you're attempting to do, and how you have it set up.
     
    • Agree Agree x 1
  16. ok so, What i am doing is saving a UUID to the config

    5749w8650ejldh gfd hg (What ever):
    and then giving it a value

    5749w8650ejldh gfd hg: <Nickname>
    Then when they join i get there UUID and the string and apply the Name
     
  17. But idk how to get it :D
     
  18. Save the players UUID to your file:
    Code (Text):
    yourConfig.set(player.getUniqueId().toString();
    Check if the player exists in the file:
    Code (Text):
    if(yourConfig.getString(player.getUniqueId().toString()) != null) {
    UUID id = UUID.fromString(yourConfig.getString(player.getUniqueId().toString());
    Not too hard, and I suggest learning a bit more about java and files.
     
  19. Thanks for not being mean at all about it!
     
    • Like Like x 1
  20. This is completely redundant and incorrect... If the value in the config is stored by UUID then you would not be returning the UUID from the config.