Usage
(4min read) Basic file operations to get started.
Last updated
(4min read) Basic file operations to get started.
Last updated
Every entry (key=value pair) in the document is represented as a .
carry the comments and the actual value (Java object).
are extensions of blocks representing values and provide plenty of methods for data accessing and modification. The is also a section - the root section.
BoostedYAML uses "routes" (URI-like objects) to access and modify data (like paths in Spigot/BungeeCord API). Please read a short article about them - you'll need it:
You can create and initially a document using any of the provided YamlDocument.create()
methods (click for JavaDoc):
Document: the actual content that will be loaded and made available to you.
Defaults: the default version of the document, usually bundled under "resources". Optional, but are required if you'd like to obtain default values of missing/invalid mappings.
All the provided objects, including settings, are now said to be associated with the document. You will come across this term many times in the documentation.
Defaults are required by the updater and can also be used to substitute missing or invalid content in the document.
You will lose access to all features listed above. But don't worry! That doesn't mean you can't load, save or update the file, you will just need to provide the input/output/defaults each time to the method you're using and you must do everything manually (talking about the settings, which will not be effective for you).
Uses the class loader to obtain the defaults and uses KeyFormat.OBJECT
(Route objects):
TIP: You're welcome to use other methods as well, if you'd like to save using custom (non-associated settings).
Use DVS (document versioning system) to index documents by their versions (revisions). This tells the updater if the document is already up to date (ensuring the best performance) and allows you to use cool and useful features the updater offers. We'll get back to that in a second.
Updates against the associated defaults (it will fail if there are not any).
TIP: Use the DVS (document versioning system) to index documents using versions (revisions).
The cool features you can use:
relocations: if you moved some content from one place in the document to another,
ignored routes: for sections which users can freely extend (whose content is not strictly defined),
mappers: if you changed the datatype of the value, for example for settings which were true/false but are represented by an enum now,
custom logic: apply custom logic to the document - access, delete, change data your way.
You can associate new settings at any time using the following method:
The given settings will be now associated with the document.
This method has replaced the 4 association methods listed below since v1.3.2. These are now deprecated and subject for removal:
WARNING!
Always refer to the method documentation, as there are a few limitations to mind and be aware of when re-associating settings.
There are 4 types of settings you can provide: , , and . These modify the behaviour of the documents during runtime, loading, dumping and updating.
If you chose to use KeyFormat.OBJECT
(article about ) provide it here via (KeyFormat.STRING
is the default).
If you want to continue using , provide custom with the Spigot-compatible serializer:
This serializer is only a bridge between BoostedYAML and the Spigot's serialization system. To register classes for serialization, use just as you have been.
If you give the document as an instance of , it will be automatically and (yes, everything is customizable). It will be used as input/output, so you can use and methods wihout providing any parameter. The file itself will be accessible using .
These features are not available if the document is given as a .
Now, the benefits. By providing them, if a file is being created because it does not exist (see above), it's content and content of the loaded document will be the defaults (instead of an empty file and document). The updater will use the given defaults automatically, so you can not only use without any parameter, but also enable , so you get up-to-date data each time you (re)load the document.
Selected section methods may reach out to the defaults to substitute deleted or malformed data, or collect all available data (bulk content getters which return a collection of blocks, values, keys...). We understand that this might not be a benefit. If you'd like to provide the defaults for updater and file creation purposes and consumption benefits, but don't want this behaviour, disable .
Configuration compatible with current state of the Spigot/BungeeCord file and serialization API (as stated above, continue using to register your classes):
Reloads from the associated (it will fail if there is not any).
The behaviour is the same as loading initially and if the file does not exist, the document will be reloaded from a copy of the defaults (or empty if there are not any). It will also automatically be to the file (enabled by default).
Reloads from the provided .
If the file does not exist, the document will be reloaded from a copy of the defaults (or empty if there are not any). It will also automatically be to the file (enabled by default).
Reloads from the provided .
TIP: No matter the method you use, if there are any defaults, you can enable (disabled by default), which will ensure your document is always up to date.
Saves to the associated (it will fail if there is not any) with UTF-8 charset.
Saves to the provided with UTF-8 charset.
To ensure you have always up to date document, it is recommended to call this method after creation and each reload. Or, let BoostedYAML all of this for you automatically by enabling .
If there's any associated , the document will be (enabled by default).
If the document is already up to date, it does not need an update. Document versions tell the updater if this is case and also allows you to use plenty of cool and useful features it offers. Read quick setup (~2 min).