Refactor RegexObject to ChatFilter and ChatFilterType

This commit is contained in:
len 2021-05-20 18:47:22 +02:00
parent 4124315bd7
commit 8fc9e0c447
3 changed files with 11 additions and 12 deletions

View File

@ -2,7 +2,7 @@ package com.alttd.chat.managers;
import com.alttd.chat.config.Config; import com.alttd.chat.config.Config;
import com.alttd.chat.config.RegexConfig; import com.alttd.chat.config.RegexConfig;
import com.alttd.chat.objects.RegexType; import com.alttd.chat.objects.ChatFilterType;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import ninja.leaping.configurate.ConfigurationNode; import ninja.leaping.configurate.ConfigurationNode;
@ -14,7 +14,6 @@ import java.util.regex.Pattern;
public class RegexManager { public class RegexManager {
// todo move this to API!
private static final HashMap<Pattern, ArrayList<String>> cancelRegex = new HashMap<>(); private static final HashMap<Pattern, ArrayList<String>> cancelRegex = new HashMap<>();
private static final HashMap<String, String> replaceRegex = new HashMap<>(); private static final HashMap<String, String> replaceRegex = new HashMap<>();
@ -24,9 +23,9 @@ public class RegexManager {
// maiby a REGEXobject and a list<Regex> would be better here? // maiby a REGEXobject and a list<Regex> would be better here?
for(ConfigurationNode node : Config.REGEXNODE.getChildrenMap().values()) { for(ConfigurationNode node : Config.REGEXNODE.getChildrenMap().values()) {
RegexConfig regexConfig = new RegexConfig(node.getString()); RegexConfig regexConfig = new RegexConfig(node.getString());
if (RegexType.getType(regexConfig.TYPE) == RegexType.BLOCK) { if (ChatFilterType.getType(regexConfig.TYPE) == ChatFilterType.BLOCK) {
cancelRegex.put(Pattern.compile(regexConfig.REGEX), Lists.newArrayList(regexConfig.REPLACEMENT)); cancelRegex.put(Pattern.compile(regexConfig.REGEX), Lists.newArrayList(regexConfig.REPLACEMENT));
} else if (RegexType.getType(regexConfig.TYPE) == RegexType.REPLACE) { } else if (ChatFilterType.getType(regexConfig.TYPE) == ChatFilterType.REPLACE) {
replaceRegex.put(regexConfig.REGEX, regexConfig.REPLACEMENT); replaceRegex.put(regexConfig.REGEX, regexConfig.REPLACEMENT);
} }
} }

View File

@ -3,15 +3,15 @@ package com.alttd.chat.objects;
public class ChatFilter { public class ChatFilter {
private final String regex; private final String regex;
private final RegexType type; private final ChatFilterType type;
private String replacement = ""; private String replacement = "";
public ChatFilter(String regex, RegexType type) { public ChatFilter(String regex, ChatFilterType type) {
this.regex = regex; this.regex = regex;
this.type = type; this.type = type;
} }
public ChatFilter(String regex, RegexType type, String replacement) { public ChatFilter(String regex, ChatFilterType type, String replacement) {
this.regex = regex; this.regex = regex;
this.type = type; this.type = type;
this.replacement = replacement; this.replacement = replacement;
@ -21,7 +21,7 @@ public class ChatFilter {
return regex; return regex;
} }
public RegexType getType() { public ChatFilterType getType() {
return type; return type;
} }

View File

@ -1,17 +1,17 @@
package com.alttd.chat.objects; package com.alttd.chat.objects;
public enum RegexType { public enum ChatFilterType {
REPLACE("replace"), REPLACE("replace"),
BLOCK("block"); BLOCK("block");
private final String name; private final String name;
RegexType(String name) { ChatFilterType(String name) {
this.name = name; this.name = name;
} }
public static RegexType getType(String name) { public static ChatFilterType getType(String name) {
for (RegexType type : RegexType.values()) { for (ChatFilterType type : ChatFilterType.values()) {
if (type.name.equalsIgnoreCase(name)) { if (type.name.equalsIgnoreCase(name)) {
return type; return type;
} }