Don't use replacematcher for parsing text on signs
This commit is contained in:
parent
a35ad9ebeb
commit
1d5dd7c764
|
|
@ -77,9 +77,6 @@ public class ChatImplementation implements ChatAPI{
|
||||||
prefixes = new HashMap<>();
|
prefixes = new HashMap<>();
|
||||||
getLuckPerms().getGroupManager().getLoadedGroups().stream()
|
getLuckPerms().getGroupManager().getLoadedGroups().stream()
|
||||||
.map(Group::getName).forEach(groupName -> prefixes.put(groupName, new PrefixConfig(groupName).PREFIXFORMAT));
|
.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 File CONFIGPATH;
|
||||||
public static void init() { // todo setup share for the config
|
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");
|
CONFIG_FILE = new File(CONFIGPATH, "config.yml");
|
||||||
configLoader = YAMLConfigurationLoader.builder()
|
configLoader = YAMLConfigurationLoader.builder()
|
||||||
.setFile(CONFIG_FILE)
|
.setFile(CONFIG_FILE)
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,8 @@ public final class PrefixConfig {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File CONFIGPATH;
|
|
||||||
public void init() {
|
public void init() {
|
||||||
CONFIGPATH = new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "ChatPlugin");
|
CONFIG_FILE = new File(Config.CONFIGPATH, "prefix.yml");
|
||||||
CONFIG_FILE = new File(CONFIGPATH, "prefix.yml");
|
|
||||||
configLoader = YAMLConfigurationLoader.builder()
|
configLoader = YAMLConfigurationLoader.builder()
|
||||||
.setFile(CONFIG_FILE)
|
.setFile(CONFIG_FILE)
|
||||||
.setFlowStyle(DumperOptions.FlowStyle.BLOCK)
|
.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
|
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);
|
User user = ChatAPI.get().getLuckPerms().getUserManager().getUser(uuid);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
ALogger.warn("Tried to check chat filters for a user who doesn't exist in LuckPerms");
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
break;
|
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;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,4 +57,19 @@ public class ChatFilter {
|
||||||
}
|
}
|
||||||
return input;
|
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) {
|
public static String getGroupPrefix(Group group) {
|
||||||
return ChatAPI.get().getPrefixes().get(group.getName()).replace("<prefix>", group.getCachedData().getMetaData().getPrefix());
|
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) {
|
public static String getDisplayName(UUID uuid, String playerName) {
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ public class PlayerListener implements Listener {
|
||||||
if (component != null) {
|
if (component != null) {
|
||||||
String message = PlainComponentSerializer.plain().serialize(component);
|
String message = PlainComponentSerializer.plain().serialize(component);
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
message = RegexManager.replaceText(player.getName(), player.getUniqueId(), message); // todo a better way for this
|
message = RegexManager.replaceText(player.getName(), player.getUniqueId(), message, false); // todo a better way for this
|
||||||
|
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
GalaxyUtility.sendBlockedNotification("Sign Language" , player, PlainComponentSerializer.plain().serialize(component), "");
|
GalaxyUtility.sendBlockedNotification("Sign Language" , player, PlainComponentSerializer.plain().serialize(component), "");
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
@ -33,7 +34,19 @@ public class PluginMessage implements PluginMessageListener {
|
||||||
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
|
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
|
||||||
String subChannel = in.readUTF();
|
String subChannel = in.readUTF();
|
||||||
switch (subChannel) {
|
switch (subChannel) {
|
||||||
case "privatemessage": {
|
case "privatemessagein": {
|
||||||
|
UUID uuid = UUID.fromString(in.readUTF());
|
||||||
|
String target = in.readUTF();
|
||||||
|
Player p = Bukkit.getPlayer(uuid);
|
||||||
|
if (p != null) {
|
||||||
|
p.sendMessage(GsonComponentSerializer.gson().deserialize(in.readUTF()));
|
||||||
|
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1); // todo load this from config
|
||||||
|
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||||
|
user.setReplyTarget(target);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "privatemessageout": {
|
||||||
UUID uuid = UUID.fromString(in.readUTF());
|
UUID uuid = UUID.fromString(in.readUTF());
|
||||||
String target = in.readUTF();
|
String target = in.readUTF();
|
||||||
Player p = Bukkit.getPlayer(uuid);
|
Player p = Bukkit.getPlayer(uuid);
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ public class ChatHandler {
|
||||||
serverConnection = player.getCurrentServer().get();
|
serverConnection = player.getCurrentServer().get();
|
||||||
Component component = miniMessage.parse(Config.MESSAGESENDER, templates);
|
Component component = miniMessage.parse(Config.MESSAGESENDER, templates);
|
||||||
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
||||||
buf.writeUTF("privatemessage");
|
buf.writeUTF("privatemessageout");
|
||||||
buf.writeUTF(player.getUniqueId().toString());
|
buf.writeUTF(player.getUniqueId().toString());
|
||||||
buf.writeUTF(player2.getUsername());
|
buf.writeUTF(player2.getUsername());
|
||||||
buf.writeUTF(GsonComponentSerializer.gson().serialize(component));
|
buf.writeUTF(GsonComponentSerializer.gson().serialize(component));
|
||||||
|
|
@ -63,7 +63,7 @@ public class ChatHandler {
|
||||||
serverConnection = player2.getCurrentServer().get();
|
serverConnection = player2.getCurrentServer().get();
|
||||||
component = miniMessage.parse(Config.MESSAGERECIEVER, templates);
|
component = miniMessage.parse(Config.MESSAGERECIEVER, templates);
|
||||||
buf = ByteStreams.newDataOutput();
|
buf = ByteStreams.newDataOutput();
|
||||||
buf.writeUTF("privatemessage");
|
buf.writeUTF("privatemessagein");
|
||||||
buf.writeUTF(player2.getUniqueId().toString());
|
buf.writeUTF(player2.getUniqueId().toString());
|
||||||
buf.writeUTF(player.getUsername());
|
buf.writeUTF(player.getUsername());
|
||||||
buf.writeUTF(GsonComponentSerializer.gson().serialize(component));
|
buf.writeUTF(GsonComponentSerializer.gson().serialize(component));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user