Saving data to a YAML configuration
Now we are ready to complete the save
method. We want to save our data to a YAML file much like config.yml
. However, we do not want to save it to config.yml
, because that serves a different purpose. The first thing we will need to do is to create a new YAML configuration:
YamlConfiguration config = new YamlConfiguration();
Next, we will store all of the information that we wish to save. This is done by setting objects to specific paths:
config.set(String path, Object value);
The acceptable types for value
were mentioned earlier in this chapter. In our teleportation plugin, we have hashmaps, which contain our SerializableLocations
method. Hashmaps can be added to a YAML configuration as long as they are a map of strings to an object that is ConfigurationSerializable
. Hashmaps are added to a configuration in a different manner. You must create a configuration section using the map.
The following code shows how we will add our teleportation data to our configuration...