Single Type Config Directory
A directory of configuration files that store a single type of class.
public class Example implements ConfigurationConvertible<Example> {
public String string;
@Override
public @NotNull ConfigurationSection convert() {
ConfigurationSection section = new MemoryConfigurationSection();
section.set("string", string);
return section;
}
@Override
public @NotNull Example convert(@NotNull ConfigurationSection section) {
this.string = section.getString("string");
return this;
}
}
SingleTypeConfigurationDirectory<Example> directory
= new SingleTypeConfigurationDirectory<>(
new File(""),
identifier -> new Example(),
false
);
directory.set("identifier", new Example());
Example example = directory.get("identifier").orElseThrow();
directory.remove("identifier");
boolean contains = directory.contains("identifier");
It will save every time you write to it.
If you have multiple directory instances, there could be read/write colisions!
Last updated