messages: '0': task: Example Normal Task done: false urgency: '1' added-by: CONSOLE '1': task: Example Important Task done: false urgency: '2' added-by: CONSOLEThis is for a new plugin I'm writing called BukkitList, and I have a command to remove a task, and to do that, I have it set to fetch a configuration section ("messages") & getKeys(false), and remove the specified node, then to set that conf. section back to "messages", but as I've realized, this will empty all the nodes under the remaining nodes. How can I get rid of one node under "messages" and all it's sub-nodes, and leave the others intact? Apparently I have fascination with using conf. sections @.@ I tried it without the getKeys(false) part, but that changes the data type of the variable, then I can't remove items from it. Or I should say I don't know how. T.T
How to delete a node and all sub values? (Bukkit of course)
How to delete a node and all sub values? (Bukkit of course)
I have a yml file here:
Re: How to delete a node and all sub values? (Bukkit of cour
Well what you tried sounds right, I think the argument to getKeys() controls if the child nodes should also be returned, so if you set that to true it should keep the rest of the data in place.
You might not need to set it back to the main config too, if the list is live you won't need too. I don't know if it is or not but it might be worth trying since you can do it in a one-liner
You might not need to set it back to the main config too, if the list is live you won't need too. I don't know if it is or not but it might be worth trying since you can do it in a one-liner
this.config.getConfigurationSection("messages").getKeys(true).remove("1");
Re: How to delete a node and all sub values? (Bukkit of cour
Jeeze, never thought to try getKeys(true), I always set it false or left it out entirely (which changed the varible data type), and the .remove() wasn't supported for that data type. But yes, I'll try it. I do somewhat need to save back to the file though. I like to save the file after every edit so that they can reload (which won't save the file since it's saved during every edit, but reloads the files). Somewhat of a method I prefer. I hate it when I edit a file, reload it, then it rewrites the old file back. Just dreadful annoying. Always hafta shut down the server to edit it.
Re: How to delete a node and all sub values? (Bukkit of cour
Good point, I hate that too. I sometime open the file just before the server shutdown fully too. That's much more irritting !offluffy wrote:I hate it when I edit a file, reload it, then it rewrites the old file back. Just dreadful annoying. Always hafta shut down the server to edit it.
Re: How to delete a node and all sub values? (Bukkit of cour
Sorry to revive this, but I'm having some issues with this. So I start with something like this for a yml file:
This is the code I'm using to remove the node:
Borders: test: Owner: OffLuffy Position: 0,64,0 Radius: 100 Shape: roundThen I can add to the file fine and it works perfectly, but when I go to remove a node like test, it turns into this:
Borders: !!set test: null test.Owner: null test.Position: null test.Radius: null test.Shape: nullAny clue why it's doing this or how to fix this?
This is the code I'm using to remove the node:
// For reference: String world = "test"; Set<String> cfs = plugin.borders.getConfigurationSection("Borders").getKeys(true); cfs.remove(world); plugin.borders.set("Borders", cfs); try{ plugin.borders.save(plugin.bordersFile); }catch (IOException e){ e.printStackTrace(); }
Re: How to delete a node and all sub values? (Bukkit of cour
The config section should not be a set of strings. It should be a ConfigurationSection
So change
So change
Set<String> cfs = plugin.borders.getConfigurationSection("Borders").getKeys(true);To
ConfigurationSection cfs = plugin.borders.getConfigurationSection("Borders").getKeys(true);and you should be okay.
Re: How to delete a node and all sub values? (Bukkit of cour
Not entirely sure how that'd work O.o I can set it to a ConfigurationSection if I cast it from a Set<String>, but then the ConfigurationSection doesn't have a .remove() method. So I guess in the mean time, I'll just remove the getKeys(true), and work from there.
Re: How to delete a node and all sub values? (Bukkit of cour
Oh sorry I misread it.
I checked the javadoc and found
I checked the javadoc and found
So maybe tryIf value is null, the value will be removed from the default Configuration source.
plugin.borders.set("Borders." + world, null);?
Re: How to delete a node and all sub values? (Bukkit of cour
I tried it right quick and it seems to do the same thing. Just splits all the nodes into a single-tier level list with null values.
EDIT:
Scratch that, kinda sorta changed the wrong line of code. Will post again later with the right result I guess XDD
MORE EDITS:
Alright, that seems to work XD After using that, it sets it to this if there's no more sub-nodes:
EDIT:
Scratch that, kinda sorta changed the wrong line of code. Will post again later with the right result I guess XDD
MORE EDITS:
Alright, that seems to work XD After using that, it sets it to this if there's no more sub-nodes:
Borders: {}Which works well enough for me. Doesn't spit back errors or anything.
Re: How to delete a node and all sub values? (Bukkit of cour
Looks good, I think {} just indicates an empty node.
Re: How to delete a node and all sub values? (Bukkit of cour
Seems so. More-so I think it indicates an empty multi-tier node. And empty single-tier node usually has a "[]" after it. And thanks! This slight issue with node removal has been hindering me from updating about 3 of my plugins in the works XDD Great help, appreciate it @.@