Closed Osiris-Team closed 4 years ago
there are getValues(boolean) and getMapValue(boolean) methods to get values of the each section.
@portlek Lets take it a step further and say that I don't know the path ("name" and "last-name") but I want to get a list or map containing all information.
as i said, you can get the values with getValues and getMapValues methods, you don't have to know these name or last-name section.
Ok great thx
when you use getValues(boolean) method it returns a map that looks like:
{
"name": "John",
"last-name": "Stamos"
}
@portlek Another question. Will this still work if we talk about a yml file that only exists in the memory?
Probably yes, the library is using MemorySection
so it stores in the memory, and you will get these values from it.
@portlek Thanks for helping btw. But there is something more ^^ The map returns an object, but i need to know what object it is(List, String...). How do I do that?
just use instanceof
which is a Java feature.
For single values you can use get(String path)
. If you know types you can use direct methods like getString
or getInt
. If you don't know the path of keys then use getValues
or getMapValues
.
If you know the path of keys but don't know the type of the value there are methods to check its type like isString
or isInt
.
Have a look to all available methods of ConfigurationSection
here.
And yes, all changes are made in memory. File is only read on load and written on save. You can even have a YamlFile without any file too (entirely in memory).
Lets say I have a file called person.yml and I want to get the values for "name" and "last-name".
Is there a way doing this with simple yaml?