Push progress

This commit is contained in:
len
2021-06-06 21:32:13 +02:00
parent 5d8d7b5dff
commit 198e80aa7a
15 changed files with 242 additions and 140 deletions
@@ -14,6 +14,7 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
@@ -29,10 +30,10 @@ public final class Config {
static int version;
static boolean verbose;
public static void init(File path) {
CONFIG_FILE = new File(path, "config.yml");;
// public static void init() { // todo setup share for the config
// CONFIG_FILE = new File(new File(System.getProperty("user.home")+File.separator+"ChatPlugin"), "config.yml");;
public static File CONFIGPATH;
public static void init() { // todo setup share for the config
CONFIGPATH = new File(System.getProperty("user.home")+File.separator+"ChatPlugin");
CONFIG_FILE = new File(CONFIGPATH, "config.yml");;
configLoader = YAMLConfigurationLoader.builder()
.setFile(CONFIG_FILE)
.setFlowStyle(DumperOptions.FlowStyle.BLOCK)
@@ -186,13 +187,16 @@ public final class Config {
public static String GCFORMAT = "<white><light_purple><prefix></light_purple> <gray><sender></gray> <hover:show_text:on <server>><yellow>to Global</yellow></hover><gray>: <message>";
public static String GCPERMISSION = "proxy.globalchat";
public static List<String> GCALIAS = new ArrayList<>();
public static String GCNOTENABLED = "You don't have global chat enabled.";
public static String GCNOTENABLED = "You don't have global chat enabled."; // todo mini message formatting
public static String GCONCOOLDOWN = "You have to wait <cooldown> seconds before using this feature again."; // todo mini message formatting
public static int GCCOOLDOWN = 30;
private static void globalChat() {
MESSAGERECIEVER = getString("commands.globalchat.format", MESSAGERECIEVER);
GCPERMISSION = getString("commands.globalchat.view-chat-permission", GCPERMISSION);
GCALIAS.clear();
GCALIAS = getList("commands.globalchat.alias", Lists.newArrayList("gc", "global"));
GCNOTENABLED = getString("commands.globalchat.not-enabled", GCNOTENABLED);
GCCOOLDOWN = getInt("commands.globalchat.cooldown", GCCOOLDOWN);
}
public static List<String> GACECOMMANDALIASES = new ArrayList<>();
@@ -1,11 +1,12 @@
package com.alttd.chat.config;
import com.alttd.chat.managers.RegexManager;
import com.alttd.chat.objects.ChatFilter;
import com.google.common.base.Throwables;
import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.ConfigurationOptions;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
import org.yaml.snakeyaml.DumperOptions;
@@ -35,8 +36,8 @@ public final class RegexConfig {
static int version;
static boolean verbose;
public static void init(File path) {
CONFIG_FILE = new File(path, "filters.yml");;
public static void init() {
CONFIG_FILE = new File(Config.CONFIGPATH, "filters.yml");;
configLoader = YAMLConfigurationLoader.builder()
.setFile(CONFIG_FILE)
.setFlowStyle(DumperOptions.FlowStyle.BLOCK)
@@ -145,40 +146,43 @@ public final class RegexConfig {
return new ArrayList<>();
}
// 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);
// }
// Options:
// Filter: the regexstring
// replacements:
// exclusions: ["list", "of", "words"]
private void loadChatFilters() {
for (Map.Entry<Object, ? extends ConfigurationNode> entry : config.getChildrenMap().entrySet()) {
String name = entry.getKey().toString(); // the name in the config this filter has
String type = entry.getValue().getNode("type").getString(); // the type of filter, block or replace
String regex = "";
List<String> replacements = new ArrayList<>();
List<String> exclusions = new ArrayList<>();
Map<Object, ? extends ConfigurationNode> options = entry.getValue().getNode("options").getChildrenMap();
if (options.containsKey("filter")) {
regex = options.get("filter").getString();
// for (Map.Entry<Object, ? extends ConfigurationNode> entry : config.getChildrenMap().entrySet()) {
// String name = entry.getKey().toString(); // the name in the config this filter has
// String type = entry.getValue().getNode("type").getString(); // the type of filter, block or replace
// String regex = "";
// List<String> replacements = new ArrayList<>();
// List<String> exclusions = new ArrayList<>();
// Map<Object, ? extends ConfigurationNode> options = entry.getValue().getNode("options").getChildrenMap();
// if (options.containsKey("filter")) {
// regex = options.get("filter").getString();
// }
// if (options.containsKey("replacements")) {
// options.get("replacements").getChildrenList().forEach(key -> {
// replacements.add(key.getString());
// });
// }
// if (options.containsKey("exclusions")) {
// options.get("exclusions").getChildrenList().forEach(key -> {
// exclusions.add(key.getString());
// });
// }
// }
Map<String, Object> properties = new HashMap<>();
config.getChildrenMap().forEach((key, value) -> {
if (value.hasMapChildren()) {
String rkey = key.toString();
properties.put("name", rkey);
for (Map.Entry<Object, ? extends ConfigurationNode> vl : value.getChildrenMap().entrySet()) {
properties.put(rkey + "." + vl.getKey(), vl.getValue().getValue());
}
} else {
properties.put(key.toString(), value.getValue());
}
if (options.containsKey("replacements")) {
options.get("replacements").getChildrenList().forEach(key -> {
replacements.add(key.getString());
});
}
if (options.containsKey("exclusions")) {
options.get("exclusions").getChildrenList().forEach(key -> {
exclusions.add(key.getString());
});
}
}
});
ChatFilter chatFilter = new ChatFilter(properties);
RegexManager.addFilter(chatFilter);
}
}