RegexConfig

This commit is contained in:
len
2021-05-13 23:05:26 +02:00
parent 35fda21ed1
commit a7c21c6aa9
4 changed files with 97 additions and 4 deletions
@@ -148,6 +148,13 @@ public final class Config {
return new ArrayList<>();
}
private static ConfigurationNode getNode(String path) {
if(config.getNode(splitPath(path)).isVirtual()) {
new RegexConfig("Dummy");
}
return config.getNode(splitPath(path));
}
/** ONLY EDIT ANYTHING BELOW THIS LINE **/
public static List<String> PREFIXGROUPS = new ArrayList<>();
public static String CONSOLENAME = "Console";
@@ -189,4 +196,9 @@ public final class Config {
MESSAGECHANNEL = getString("settings.message-channel", MESSAGECHANNEL);
}
public static ConfigurationNode REGEXNODE = null;
private static void RegexNOde() {
REGEXNODE = getNode("regex-settings");
}
}
@@ -0,0 +1,73 @@
package com.alttd.chat.config;
import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import java.util.regex.Pattern;
public final class RegexConfig {
private static final Pattern PATH_PATTERN = Pattern.compile("\\.");
private final String regexName;
private final String configPath;
public RegexConfig(String regexName) {
this.regexName = regexName;
this.configPath = "regex-settings." + this.regexName + ".";
init();
}
public void init() {
Config.readConfig(RegexConfig.class, this);
Config.saveConfig();
}
public static Object[] splitPath(String key) {
return PATH_PATTERN.split(key);
}
private static void set(String path, Object def) {
if(Config.config.getNode(splitPath(path)).isVirtual()) {
Config.config.getNode(splitPath(path)).setValue(def);
}
}
private static void setString(String path, String def) {
try {
if(Config.config.getNode(splitPath(path)).isVirtual())
Config.config.getNode(splitPath(path)).setValue(TypeToken.of(String.class), def);
} catch(ObjectMappingException ex) {
}
}
private boolean getBoolean(String path, boolean def) {
set(configPath + path, def);
return Config.config.getNode(splitPath(configPath+path)).getBoolean(def);
}
private double getDouble(String path, double def) {
set(configPath +path, def);
return Config.config.getNode(splitPath(configPath+path)).getDouble(def);
}
private int getInt(String path, int def) {
set(configPath +path, def);
return Config.config.getNode(splitPath(configPath+path)).getInt(def);
}
private String getString(String path, String def) {
set(configPath +path, def);
return Config.config.getNode(splitPath(configPath+path)).getString(def);
}
/** DO NOT EDIT ANYTHING ABOVE **/
public String REGEX = "REGEX";
public String TYPE = "TYPE";
public String REPLACEMENT = "REPLACEMENT";
private void ServerSettings() {
REGEX = getString("regex", REGEX);
TYPE = getString("type", TYPE);
REPLACEMENT = getString("replacement", REPLACEMENT);
}
}