RegexConfig
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package com.alttd.chat;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.config.RegexConfig;
|
||||
import com.alttd.chat.database.DatabaseConnection;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.LuckPermsProvider;
|
||||
import net.luckperms.api.model.group.Group;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
@@ -23,9 +25,12 @@ public class ChatImplementation implements ChatAPI{
|
||||
Config.init();
|
||||
|
||||
luckPerms = getLuckPerms();
|
||||
//databaseConnection = getDataBase();
|
||||
// init database
|
||||
// init depends//or set them the first time they are called?
|
||||
//databaseConnection = getDataBase(); // TODO fix database on proxy, shade sql, add defaults to config
|
||||
|
||||
// LOAD REGEXES, sad way of doing it:(
|
||||
for(ConfigurationNode node : Config.REGEXNODE.getChildrenMap().values()) {
|
||||
new RegexConfig(node.getString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user