Solved How to get (anything).uuid in a .yml file and compare it

Discussion in 'Plugin Development' started by Xerox262, Jun 20, 2015.

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

    Xerox262

    Config file for reference

    Code:
    test:
      world: world
      x: 94.69999998807907
      y: 71.0
      z: -28.69999998807907
      yaw: 2.25
      pitch: 1.0500001
      uuid: af5d766c-b8b9-34ea-a7e0-3e835cdee780
    test2:
      world: world
      x: 82.9647221257064
      y: 74.0
      z: -24.66694902763564
      yaw: 1.500061
      pitch: 4.649993
      uuid: af5d766c-b8b9-34ea-a7e0-3e835cdee780
    From the configs you could probably tell that this is for a warp plugin. I just hit a barrier however trying to make it so a player is limited to a certain amount of warps, this way I could allow every player on my server have 1 public warp for a shop without giving them the permissions to create as many as they want, so I was just wondering is there a method for getting every configuration section like test, test.world, test.x, test.z, etc. or atleast a way to check all configuration sections to see if any end with .uuid
     
  2. Offline

    Xerox262

    bump

    Removed the code I had because KinfFaris11's is the correct way to do it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  3. ^ No no no, I'm creating the real way now...
     
  4. Offline

    Xerox262

    @KingFaris11 I didn't want to resort to that to get what I needed, but I was getting impatient xI
     
  5. Code:
    public List<String> getWarpsByUUID(UUID playerUUID) {
        List<String> playerWarps = new ArrayList<>();
        for (Map.Entry<String, Object> configEntry : config.getValues(false).entrySet()) { // Loop through every configuration key, e.g. "Hi: true", "Bye: false", the key would  be "Hi" and "Bye", the value would be a Boolean (as an Object) "true" and "false".
            if (configEntry.getValue() instanceof ConfigurationSection) { // Check if the value of the property is a ConfigurationSection, as you don't want to check a key that's like, a boolean.
                ConfigurationSection warpSection = (ConfigurationSection) configEntry.getValue();
                if (warpSection.getString("uuid", "").equals(playerUUID.toString())) playerWarps.add(configEntry.getKey()); // Get the UUID in the configuration section (default ""), and if it's equal to the player's UUID, add it to the list of warps.
            }
        }
        return playerWarps;
    }
    
    I made it so it returns the warps as a List, not the number of warps. This way, you can use this for multiple things, not only getting the size (getWarpsByUUID(player.getUniqueId()).size())

    Haha yeah, I don't know why anyone didn't reply? It's a very simple thing to do if you know how the configuration API works fully, which many people do...
     
    Last edited: Jun 22, 2015
    Xerox262 likes this.
  6. Offline

    Xerox262

  7. No problem :p I edited it with comments to explain it if you wanted to know how it works xD
     
Thread Status:
Not open for further replies.

Share This Page