Changes to AbstractConfig.java
This commit is contained in:
parent
1157b90d51
commit
8d883b1e88
|
|
@ -22,14 +22,14 @@ import java.util.Map;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@SuppressWarnings({"unused", "SameParameterValue"})
|
@SuppressWarnings({"unused", "SameParameterValue"})
|
||||||
abstract class AbstractConfig {
|
public abstract class AbstractConfig {
|
||||||
private static final Pattern PATH_PATTERN = Pattern.compile("\\.");
|
private static final Pattern PATH_PATTERN = Pattern.compile("\\.");
|
||||||
private static final String HEADER = "";
|
private static final String HEADER = "";
|
||||||
|
|
||||||
private YamlConfigurationLoader configLoader;
|
private YamlConfigurationLoader configLoader;
|
||||||
private ConfigurationNode config;
|
private ConfigurationNode config;
|
||||||
|
|
||||||
AbstractConfig(String filename) {
|
protected AbstractConfig(String filename) {
|
||||||
init(new File(new File(AltitudeBot.getInstance().getDataFolder()).getParentFile(), filename), filename);
|
init(new File(new File(AltitudeBot.getInstance().getDataFolder()).getParentFile(), filename), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,7 +60,7 @@ abstract class AbstractConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void readConfig(Class<?> clazz, Object instance) {
|
protected void readConfig(Class<?> clazz, Object instance) {
|
||||||
for (Method method : clazz.getDeclaredMethods()) {
|
for (Method method : clazz.getDeclaredMethods()) {
|
||||||
if (Modifier.isPrivate(method.getModifiers())) {
|
if (Modifier.isPrivate(method.getModifiers())) {
|
||||||
if (method.getParameterTypes().length == 0 && method.getReturnType() == Void.TYPE) {
|
if (method.getParameterTypes().length == 0 && method.getReturnType() == Void.TYPE) {
|
||||||
|
|
@ -80,7 +80,7 @@ abstract class AbstractConfig {
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void save() {
|
protected void save() {
|
||||||
try {
|
try {
|
||||||
configLoader.save(config);
|
configLoader.save(config);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
|
@ -101,6 +101,17 @@ abstract class AbstractConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void update(String path, Object def) {
|
||||||
|
if(config.node(splitPath(path)).virtual()) {
|
||||||
|
set(path, def);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
config.node(splitPath(path)).set(def);
|
||||||
|
} catch (SerializationException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void setString(String path, String def) {
|
protected void setString(String path, String def) {
|
||||||
try {
|
try {
|
||||||
if(config.node(splitPath(path)).virtual())
|
if(config.node(splitPath(path)).virtual())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user