Use exceptions for filters, highlight words that were filtered
This commit is contained in:
@@ -3,15 +3,14 @@ package com.alttd.chat.managers;
|
||||
import com.alttd.chat.ChatAPI;
|
||||
import com.alttd.chat.config.RegexConfig;
|
||||
import com.alttd.chat.objects.ChatFilter;
|
||||
import com.alttd.chat.objects.ModifiableString;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.cacheddata.CachedPermissionData;
|
||||
import net.luckperms.api.model.user.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class RegexManager {
|
||||
@@ -29,15 +28,15 @@ public class RegexManager {
|
||||
chatFilters.add(filter);
|
||||
}
|
||||
|
||||
public static String replaceText(String playerName, UUID uuid, String text) { // TODO loop all objects in the list and check if they violate based on the MATCHER
|
||||
return replaceText(playerName, uuid, text, true);
|
||||
public static boolean filterText(String playerName, UUID uuid, ModifiableString modifiableString, String channel) { // TODO loop all objects in the list and check if they violate based on the MATCHER
|
||||
return filterText(playerName, uuid, modifiableString, true, channel);
|
||||
}
|
||||
|
||||
public static String replaceText(String playerName, UUID uuid, String text, boolean matcher) {
|
||||
public static boolean filterText(String playerName, UUID uuid, ModifiableString modifiableString, boolean matcher, String channel) {
|
||||
User user = ChatAPI.get().getLuckPerms().getUserManager().getUser(uuid);
|
||||
if (user == null) {
|
||||
ALogger.warn("Tried to check chat filters for a user who doesn't exist in LuckPerms");
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
CachedPermissionData permissionData = user.getCachedData().getPermissionData();
|
||||
for(ChatFilter chatFilter : chatFilters) {
|
||||
@@ -45,22 +44,24 @@ public class RegexManager {
|
||||
case CHAT:
|
||||
break;
|
||||
case REPLACE:
|
||||
text = chatFilter.replaceText(text);
|
||||
chatFilter.replaceText(modifiableString);
|
||||
break;
|
||||
case BLOCK:
|
||||
if(chatFilter.matches(text) && !permissionData.checkPermission("chat.bypass-filter." + chatFilter.getName()).asBoolean()) { // todo find a better way to do this?
|
||||
if(!permissionData.checkPermission("chat.bypass-filter-channel." + channel).asBoolean() &&
|
||||
!permissionData.checkPermission("chat.bypass-filter." + chatFilter.getName()).asBoolean() &&
|
||||
chatFilter.matches(modifiableString)) { // todo find a better way to do this?
|
||||
ALogger.info(playerName + " triggered the chat filter for " + chatFilter.getName() + ".");
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case REPLACEMATCHER:
|
||||
if(matcher) {
|
||||
text = chatFilter.replaceMatcher(text);
|
||||
chatFilter.replaceMatcher(modifiableString);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return text;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user