merge api into velocity
This commit is contained in:
@@ -2,9 +2,7 @@ package com.alttd.chat.handlers;
|
||||
|
||||
import com.alttd.chat.VelocityChat;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.data.ChatUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.alttd.chat.handlers;
|
||||
|
||||
import com.alttd.chat.data.ChatUser;
|
||||
import com.alttd.chat.data.Mail;
|
||||
import com.alttd.chat.data.ServerWrapper;
|
||||
import com.alttd.chat.database.Queries;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class ChatUserManager {
|
||||
|
||||
private static CopyOnWriteArrayList<ChatUser> chatUsers;// not sure on this, could cause errors later on
|
||||
|
||||
public static void initialize() {
|
||||
chatUsers = new CopyOnWriteArrayList<>();
|
||||
Queries.loadChatUsers();
|
||||
}
|
||||
|
||||
public static void addUser(ChatUser user) {
|
||||
if(getChatUser(user.getUuid()) != null)
|
||||
chatUsers.add(user);
|
||||
}
|
||||
|
||||
public static ChatUser getChatUser(UUID uuid) {
|
||||
for(ChatUser user : chatUsers) {
|
||||
if(user.getUuid() == uuid) {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Mail> getUnReadMail(ChatUser user) {
|
||||
return user.getMails().stream()
|
||||
.filter(Mail::isUnRead)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.alttd.chat.handlers;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.config.RegexConfig;
|
||||
import com.alttd.chat.data.FilterType;
|
||||
import com.google.common.collect.Lists;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
// TODO rebuild this class, All regexes go in a single list where we use the ChatFilter object and a matcher
|
||||
public class RegexManager {
|
||||
|
||||
private static final HashMap<Pattern, ArrayList<String>> cancelRegex = new HashMap<>();
|
||||
private static final HashMap<String, String> replaceRegex = new HashMap<>();
|
||||
|
||||
// IDEA: Regex object -> RegexPattern, shatteredPattern, replacement, replacements
|
||||
public static void initRegex() {
|
||||
// LOAD REGEXES, sad way of doing it:(
|
||||
// maiby a REGEXobject and a list<Regex> would be better here?
|
||||
for(ConfigurationNode node : Config.REGEXNODE.getChildrenMap().values()) {
|
||||
RegexConfig regexConfig = new RegexConfig(node.getString());
|
||||
if (FilterType.getType(regexConfig.TYPE) == FilterType.BLOCK) {
|
||||
cancelRegex.put(Pattern.compile(regexConfig.REGEX), Lists.newArrayList(regexConfig.REPLACEMENT));
|
||||
} else if (FilterType.getType(regexConfig.TYPE) == FilterType.REPLACE) {
|
||||
replaceRegex.put(regexConfig.REGEX, regexConfig.REPLACEMENT);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO load data from config (a regex string, and it's exceptions if there are any)
|
||||
cancelRegex.put(Pattern.compile("\\b([R]+[^\\w]?[4A]+[^\\w]?[P]+(([^\\w]?[E3]+[^\\w]?[DT]*)|([^\\w]?[I!1]+[^\\w]?[S5]+[^\\w]?[T7]+)|([^\\w]?[I!1]+[^\\w]?[N]+[^\\w]?[G69]+)))\\b"), new ArrayList<>());
|
||||
//TODO load data from config (a regex string and what to replace it with)
|
||||
replaceRegex.put(":pirate:", "pirate");
|
||||
|
||||
//TODO we might just be able to throw it all in one list and just go through it and check the type to see what to do if there is a match :eyes:
|
||||
}
|
||||
|
||||
public static boolean violatesFilter(String text) {
|
||||
for (Map.Entry<Pattern, ArrayList<String>> entry : cancelRegex.entrySet()) {
|
||||
Matcher matcher = entry.getKey().matcher(text);
|
||||
while (matcher.find()) {
|
||||
if (!entry.getValue().contains(matcher.group())) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String replaceText(String text) {
|
||||
for (Map.Entry<String, String> entry : replaceRegex.entrySet()) {
|
||||
text = text.replaceAll(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user