Don't use replacematcher for parsing text on signs
This commit is contained in:
@@ -77,9 +77,6 @@ public class ChatImplementation implements ChatAPI{
|
||||
prefixes = new HashMap<>();
|
||||
getLuckPerms().getGroupManager().getLoadedGroups().stream()
|
||||
.map(Group::getName).forEach(groupName -> prefixes.put(groupName, new PrefixConfig(groupName).PREFIXFORMAT));
|
||||
for (Map.Entry<String, String> entry : prefixes.entrySet()) {
|
||||
ALogger.info("prefix: " + entry.getKey() + " format: " + entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public final class Config {
|
||||
|
||||
public static File CONFIGPATH;
|
||||
public static void init() { // todo setup share for the config
|
||||
CONFIGPATH = new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "ChatPlugin");
|
||||
CONFIGPATH = new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "ChatPlugin");
|
||||
CONFIG_FILE = new File(CONFIGPATH, "config.yml");
|
||||
configLoader = YAMLConfigurationLoader.builder()
|
||||
.setFile(CONFIG_FILE)
|
||||
|
||||
@@ -36,10 +36,8 @@ public final class PrefixConfig {
|
||||
init();
|
||||
}
|
||||
|
||||
public static File CONFIGPATH;
|
||||
public void init() {
|
||||
CONFIGPATH = new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "ChatPlugin");
|
||||
CONFIG_FILE = new File(CONFIGPATH, "prefix.yml");
|
||||
CONFIG_FILE = new File(Config.CONFIGPATH, "prefix.yml");
|
||||
configLoader = YAMLConfigurationLoader.builder()
|
||||
.setFile(CONFIG_FILE)
|
||||
.setFlowStyle(DumperOptions.FlowStyle.BLOCK)
|
||||
|
||||
@@ -30,6 +30,10 @@ public class RegexManager {
|
||||
}
|
||||
|
||||
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 String replaceText(String playerName, UUID uuid, String text, boolean matcher) {
|
||||
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");
|
||||
@@ -49,15 +53,13 @@ public class RegexManager {
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
case REPLACEMATCHER:
|
||||
if(matcher) {
|
||||
text = chatFilter.replaceMatcher(text);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
while (matcher.find()) {
|
||||
String group = matcher.group();
|
||||
System.out.println(group);
|
||||
text = text.replace(group, group.substring(0, 3)); //TODO HARD CODED PLS PUT IN CONFIG
|
||||
System.out.println(text);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,4 +57,19 @@ public class ChatFilter {
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
public String replaceMatcher(String input) {
|
||||
int lenght;
|
||||
try {
|
||||
lenght = Integer.parseInt(replacement);
|
||||
} catch (NumberFormatException e) {
|
||||
lenght = 3; // could load this from config and make it cleaner
|
||||
}
|
||||
Matcher matcher = pattern.matcher(input);
|
||||
while (matcher.find()) {
|
||||
String group = matcher.group();
|
||||
input = input.replace(group, group.substring(0, lenght));
|
||||
}
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,22 +98,6 @@ public class Utility {
|
||||
|
||||
public static String getGroupPrefix(Group group) {
|
||||
return ChatAPI.get().getPrefixes().get(group.getName()).replace("<prefix>", group.getCachedData().getMetaData().getPrefix());
|
||||
// switch (group.getName()) { // hardcoded for now, new prefix system would load this from config
|
||||
// case "discord":
|
||||
// return "<hover:show_text:'&dNitro Booster in our discord'>" + group.getCachedData().getMetaData().getPrefix() + "</hover>";
|
||||
// case "socialmedia":
|
||||
// return "<hover:show_text:'&6Social Media, this person manages our Socials'>" + group.getCachedData().getMetaData().getPrefix() + "</hover>";
|
||||
// case "eventteam":
|
||||
// return "<hover:show_text:'&6Event Team, this person is part of the event team'>" + group.getCachedData().getMetaData().getPrefix() + "</hover>";
|
||||
// case "eventleader":
|
||||
// return "<hover:show_text:'&6Event Leader, this person is an event leader'>" + group.getCachedData().getMetaData().getPrefix() + "</hover>";
|
||||
// case "youtube":
|
||||
// return "<hover:show_text:'&6This person creates Altitude content on YouTube'>" + group.getCachedData().getMetaData().getPrefix() + "</hover>";
|
||||
// case "twitch":
|
||||
// return "<hover:show_text:'&6This person creates Altitude content on Twitch'>" + group.getCachedData().getMetaData().getPrefix() + "</hover>";
|
||||
// default:
|
||||
// return group.getCachedData().getMetaData().getPrefix();
|
||||
// }
|
||||
}
|
||||
|
||||
public static String getDisplayName(UUID uuid, String playerName) {
|
||||
|
||||
Reference in New Issue
Block a user