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

Any help topics that don't fit in the current categories can go here.
Post Reply
User avatar
offluffy
Posts: 65
Joined: Tue Mar 20, 2012 7:04 am

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

Post by offluffy »

So I have YAML file with a list of addresses such as this:

[syntax=text]Address:
127.0.0.1:
- administrator
- root
- herobrine
192.168.0.1:
- admin
- notch
- herobrine[/syntax]

Now when this file is edited with Bukkit's YAML methods, it will nest nodes like this:
[syntax=text]Address:
'127':
'0':
'0':
'1':
- administrator
- root
- herobrine
'192':
'168':
'0':
'1':
- admin
- notch
- herobrine[/syntax]
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.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

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

Post by jacek »

Strange problem !

You can do it like this in the file

[syntax=text] Address:
'127.0.0.1':
- administrator
- root
- herobrine
'192.168.0.1':
- admin
- notch
- herobrine
[/syntax]

But I'm not sure how you would do it with code.

You could try the replace thing

[syntax=java]String niceIp = ip.replace(".", "_");[/syntax]
Something like that ?
Image
User avatar
offluffy
Posts: 65
Joined: Tue Mar 20, 2012 7:04 am

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

Post 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
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

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

Post 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.
Image
User avatar
offluffy
Posts: 65
Joined: Tue Mar 20, 2012 7:04 am

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

Post 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
Post Reply