Page 1 of 1

How do I add a YAML node with periods in it?

Posted: Sat Mar 24, 2012 12:10 am
by offluffy
So I have YAML file with a list of addresses such as this:
Address:
  127.0.0.1:
  - administrator
  - root
  - herobrine
  192.168.0.1:
  - admin
  - notch
  - herobrine
Now when this file is edited with Bukkit's YAML methods, it will nest nodes like this:
Address:
  '127':
    '0':
      '0':
        '1':
        - administrator
        - root
        - herobrine
  '192':
    '168':
      '0':
        '1':
        - admin
        - notch
        - herobrine
How can I add the IP address as a single node? I'm thinking I may have to remove the dots and replace them with something with an underscore and then just replace them again when the values are read by the plugin again. And I'll do this unless there's a better way of going about this. I could leave this as is and hope it doesn't mess up much, but I intended this to be a file for Admins and I'd rather it be more readable and to have the IPs with periods. But I'll sacrifice the dots if need be.

Re: How do I add a YAML node with periods in it?

Posted: Sat Mar 24, 2012 6:39 pm
by jacek
Strange problem !

You can do it like this in the file
    Address:
      '127.0.0.1':
      - administrator
      - root
      - herobrine
      '192.168.0.1':
      - admin
      - notch
      - herobrine
But I'm not sure how you would do it with code.

You could try the replace thing
String niceIp = ip.replace(".", "_");
Something like that ?

Re: How do I add a YAML node with periods in it?

Posted: Sat Mar 24, 2012 8:27 pm
by offluffy
Yeah, I tried wrapping the IP in single-quotes, but it still breaks it up into sub-nodes. So I suppose I will try the string replace method instead XD

Re: How do I add a YAML node with periods in it?

Posted: Tue Mar 27, 2012 5:23 pm
by jacek
there doesn't actually seem to be a way :s I guess you could do it the other way around instead, store usernames with a list of IPs under them.

Re: How do I add a YAML node with periods in it?

Posted: Wed Mar 28, 2012 6:51 am
by offluffy
I actually have that also in the same file XD The reason I have it both ways is to be able to cross-reference the both of them relatively easily. Prior to this plugin, I'd have to search for someone's name in the server log, then find all the IPs they used, then go back through and search for each IP and see what names came up for each IP, etc. It was a pain. Hence why I wanted to do this XD