Saving data to a YAML configuration
Now, we are ready to complete the save
method. We want to save data to a YAML file, much like how we did in config.yml
. However, we do not want to save it to config.yml
, because that serves a different purpose. The first thing that we will need to do is create a new YAML configuration, as follows:
YamlConfiguration config = new YamlConfiguration();
Next, we will store all the information that we wish to save. This is done by setting objects to specific paths, as follows:
config.set(String path, Object value);
The acceptable types for value
were mentioned earlier in this chapter. In the teleportation plugin, we have maps, which contain the SerializableLocation
method. Maps 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 the teleportation...