Added Config#clone and JSONConfig#clone
This commit is contained in:
@@ -185,7 +185,7 @@ public interface Config extends Cloneable {
|
||||
/**
|
||||
* Get a list of strings from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @param path The key to fetch the value from.
|
||||
* @param format If the strings should be formatted.
|
||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||
*/
|
||||
@@ -236,4 +236,11 @@ public interface Config extends Cloneable {
|
||||
*/
|
||||
@Nullable
|
||||
List<Double> getDoublesOrNull(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Clone the config.
|
||||
*
|
||||
* @return The clone.
|
||||
*/
|
||||
Config clone();
|
||||
}
|
||||
|
||||
@@ -23,4 +23,7 @@ public interface JSONConfig extends Config {
|
||||
*/
|
||||
@Nullable
|
||||
List<JSONConfig> getSubsectionsOrNull(@NotNull String path);
|
||||
|
||||
@Override
|
||||
JSONConfig clone();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.willfp.eco.core.config.wrapper.YamlConfigWrapper;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
public abstract class YamlConfig extends YamlConfigWrapper {
|
||||
/**
|
||||
* Config implementation for passing YamlConfigurations.
|
||||
@@ -16,4 +18,15 @@ public abstract class YamlConfig extends YamlConfigWrapper {
|
||||
public YamlConfig(@NotNull final YamlConfiguration config) {
|
||||
super(Eco.getHandler().getConfigFactory().createYamlConfig(config));
|
||||
}
|
||||
|
||||
/**
|
||||
* Config implementation for passing YamlConfigurations.
|
||||
* <p>
|
||||
* Does not automatically update.
|
||||
*
|
||||
* @param contents The contents of the config.
|
||||
*/
|
||||
public YamlConfig(@NotNull final String contents) {
|
||||
super(Eco.getHandler().getConfigFactory().createYamlConfig(YamlConfiguration.loadConfiguration(new StringReader(contents))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,4 +150,9 @@ abstract class ConfigWrapper<T extends Config> implements Config {
|
||||
public @Nullable List<Double> getDoublesOrNull(@NotNull final String path) {
|
||||
return handle.getDoublesOrNull(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Config clone() {
|
||||
return handle.clone();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,4 +26,9 @@ public abstract class JSONConfigWrapper extends ConfigWrapper<JSONConfig> implem
|
||||
public @Nullable List<JSONConfig> getSubsectionsOrNull(@NotNull final String path) {
|
||||
return this.getHandle().getSubsectionsOrNull(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONConfig clone() {
|
||||
return this.getHandle().clone();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user