2021-07-01 20:16:25 +00:00
|
|
|
package com.fastasyncworldedit.core.configuration;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
2021-07-01 20:16:25 +00:00
|
|
|
* This is a {@link Configuration} implementation that does not save or load
|
2018-08-12 14:03:07 +00:00
|
|
|
* from any source, and stores all values in memory only.
|
|
|
|
* This is useful for temporary Configurations for providing defaults.
|
|
|
|
*/
|
|
|
|
public class MemoryConfiguration extends MemorySection implements Configuration {
|
|
|
|
protected Configuration defaults;
|
|
|
|
protected MemoryConfigurationOptions options;
|
|
|
|
|
|
|
|
/**
|
2021-07-01 20:16:25 +00:00
|
|
|
* Creates an empty {@link MemoryConfiguration} with no default values.
|
2018-08-12 14:03:07 +00:00
|
|
|
*/
|
|
|
|
public MemoryConfiguration() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-07-01 20:16:25 +00:00
|
|
|
* Creates an empty {@link MemoryConfiguration} using the specified {@link
|
|
|
|
* Configuration} as a source for all default values.
|
2018-08-12 14:03:07 +00:00
|
|
|
*
|
|
|
|
* @param defaults Default value provider
|
|
|
|
* @throws IllegalArgumentException Thrown if defaults is null
|
|
|
|
*/
|
|
|
|
public MemoryConfiguration(final Configuration defaults) {
|
|
|
|
this.defaults = defaults;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addDefault(final String path, final Object value) {
|
|
|
|
if (path == null) {
|
|
|
|
throw new NullPointerException("Path may not be null");
|
|
|
|
}
|
|
|
|
if (defaults == null) {
|
2021-07-01 20:16:25 +00:00
|
|
|
defaults = new MemoryConfiguration();
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
defaults.set(path, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addDefaults(final Map<String, Object> defaults) {
|
|
|
|
if (defaults == null) {
|
|
|
|
throw new NullPointerException("Defaults may not be null");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (final Map.Entry<String, Object> entry : defaults.entrySet()) {
|
|
|
|
addDefault(entry.getKey(), entry.getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addDefaults(final Configuration defaults) {
|
|
|
|
if (defaults == null) {
|
|
|
|
throw new NullPointerException("Defaults may not be null");
|
|
|
|
}
|
|
|
|
|
|
|
|
addDefaults(defaults.getValues(true));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setDefaults(final Configuration defaults) {
|
|
|
|
if (defaults == null) {
|
|
|
|
throw new NullPointerException("Defaults may not be null");
|
|
|
|
}
|
|
|
|
|
|
|
|
this.defaults = defaults;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Configuration getDefaults() {
|
|
|
|
return defaults;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ConfigurationSection getParent() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public MemoryConfigurationOptions options() {
|
|
|
|
if (options == null) {
|
|
|
|
options = new MemoryConfigurationOptions(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
}
|