I have this YAML file:
[syntax=text]User:
root:
- 127.0.0.1[/syntax]
And I want to be able to add a node under the "User" node (at the level where "root" is at), but when I do that, it overwrites previous nodes. I'm about 90% sure this is the wrong way to do it because I tried the handle the Set<String> just like a List<String>, but here's the code I'm using (in the LoginListener):
[syntax=java]
Set<String> userList = plugin.users.getConfigurationSection("User").getKeys(false);
if (!userList.contains(playerName.getName().toLowerCase())){
userList.add(playerName.getName().toLowerCase());
plugin.users.set("User", userList);
try{
plugin.users.save(plugin.usersFile);
}catch (IOException e){
e.printStackTrace();
}
}[/syntax]
This is basically what I want the YAML file to look like afterwards, short of the specific IP addresses and/or usernames of course:
[syntax=text]User:
root:
- 127.0.0.1
offluffy:
- 192.168.2.3[/syntax]
Unless another problem shows up, this is likely the last question you'll hear from me concerning this plugin XD Which maybe a relief to you since I started the last 4 or 5 threads in this section prior to this. .-. Hope that's not considered spamming XP
How do I add a YAML node without overwriting the others?
Re: How do I add a YAML node without overwriting the others?
I think it's because you are adding to the list of keys directly and it is not meant to be used like that. You could try adding an empty list at the position instead. Like this
[syntax=java]Set<String> userList = plugin.users.getConfigurationSection("User").getKeys(false);
if (!userList.contains(playerName.getName().toLowerCase())){
plugin.users.set("User." + playerName.getName().toLowerCase(), new ArrayList<String>());
try{
plugin.users.save(plugin.usersFile);
}catch (IOException e){
e.printStackTrace();
}
}[/syntax]
[syntax=java]Set<String> userList = plugin.users.getConfigurationSection("User").getKeys(false);
if (!userList.contains(playerName.getName().toLowerCase())){
plugin.users.set("User." + playerName.getName().toLowerCase(), new ArrayList<String>());
try{
plugin.users.save(plugin.usersFile);
}catch (IOException e){
e.printStackTrace();
}
}[/syntax]
Re: How do I add a YAML node without overwriting the others?
Well, that works well enough XD Between that and the other post about YAML nodes with periods, I think the plugin is about ready O.o I reckon I might upload this to bukkit somewhere soon XD Might test it out a bit with more users first though. And before I do all that, mind if I credit you and/or the forum here in the config.yml? O.o
I made a shiny picture for the plugin already:
I made a shiny picture for the plugin already:
Re: How do I add a YAML node without overwriting the others?
Looks good
I can never be bothered to do graphics like that, You can always release it in the work in progress section people are less likely to comment "it not work, plz update" in there
And credit is always appreciated But obviously not at all necessary.
I can never be bothered to do graphics like that, You can always release it in the work in progress section people are less likely to comment "it not work, plz update" in there
And credit is always appreciated But obviously not at all necessary.
Re: How do I add a YAML node without overwriting the others?
I posted it up on dev Bukkit XD Some people seem to think it's a good idea. And only one problem so far, which I suspect is a problem with someone editing the YML file. Anywho, here's a link if you want to take a gander => blip!
And hell, I might have time to do ya some graphics. Just ask XD I have lotz of free time and apparently not much to do with it.
And hell, I might have time to do ya some graphics. Just ask XD I have lotz of free time and apparently not much to do with it.