Add support for miniMessage serialization in chat logs
This commit is contained in:
@@ -55,7 +55,9 @@ public class ChatListener implements Listener {
|
||||
}
|
||||
|
||||
Component formatComponent = Component.text("%message%");
|
||||
ComponentLike message = parseMessageContent(event.player(), plainTextComponentSerializer.serialize(event.originalMessage()));
|
||||
ComponentLike message = parseMessageContent(event.player(),
|
||||
plainTextComponentSerializer.serialize(event.originalMessage())
|
||||
);
|
||||
|
||||
event.result(formatComponent.replaceText(TextReplacementConfig.builder().match("%message%").replacement(message).build()));
|
||||
}
|
||||
@@ -67,7 +69,9 @@ public class ChatListener implements Listener {
|
||||
}
|
||||
|
||||
Component formatComponent = Component.text("%message%");
|
||||
ComponentLike message = parseMessageContent(event.player(), plainTextComponentSerializer.serialize(event.originalMessage()));
|
||||
ComponentLike message = parseMessageContent(event.player(),
|
||||
plainTextComponentSerializer.serialize(event.originalMessage())
|
||||
);
|
||||
|
||||
event.result(formatComponent.replaceText(TextReplacementConfig.builder().match("%message%").replacement(message).build()));
|
||||
}
|
||||
@@ -92,27 +96,31 @@ public class ChatListener implements Listener {
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
ComponentLike input = event.message().colorIfAbsent(NamedTextColor.WHITE);
|
||||
Component inputComponent = input.asComponent();
|
||||
|
||||
ModifiableString modifiableString = new ModifiableString(input.asComponent());
|
||||
ModifiableString modifiableString = new ModifiableString(inputComponent);
|
||||
|
||||
// todo a better way for this
|
||||
if (!RegexManager.filterText(player.getName(), uuid, modifiableString, true, "chat", filterType -> {
|
||||
if (!filterType.equals(FilterType.PUNISH)) {
|
||||
ALogger.warn("Received another FilterType than punish when filtering chat and executing a filter action");
|
||||
return;
|
||||
}
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("punish");
|
||||
out.writeUTF(player.getName());
|
||||
out.writeUTF(uuid.toString());
|
||||
out.writeUTF(modifiableString.string());
|
||||
player.sendPluginMessage(ChatPlugin.getInstance(), Config.MESSAGECHANNEL, out.toByteArray());
|
||||
})) {
|
||||
if (!filterType.equals(FilterType.PUNISH)) {
|
||||
ALogger.warn("Received another FilterType than punish when filtering chat and executing a filter action");
|
||||
return;
|
||||
}
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("punish");
|
||||
out.writeUTF(player.getName());
|
||||
out.writeUTF(uuid.toString());
|
||||
out.writeUTF(modifiableString.string());
|
||||
player.sendPluginMessage(ChatPlugin.getInstance(), Config.MESSAGECHANNEL, out.toByteArray());
|
||||
}
|
||||
)) {
|
||||
event.setCancelled(true);
|
||||
GalaxyUtility.sendBlockedNotification("Language", player,
|
||||
modifiableString.component(),
|
||||
"");
|
||||
chatLogHandler.addChatLog(uuid, ServerName.getServerName(), PlainTextComponentSerializer.plainText().serialize(input.asComponent()), true);
|
||||
modifiableString.component(),
|
||||
""
|
||||
);
|
||||
String originalMessage = PlainTextComponentSerializer.plainText().serialize(inputComponent);
|
||||
chatLogHandler.addChatLog(uuid, ServerName.getServerName(), originalMessage, inputComponent, true);
|
||||
return; // the message was blocked
|
||||
}
|
||||
|
||||
@@ -120,7 +128,8 @@ public class ChatListener implements Listener {
|
||||
.map(audience -> (Player) audience);
|
||||
|
||||
if (!player.hasPermission("chat.ignorebypass")) {
|
||||
stream = stream.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(uuid)
|
||||
stream = stream.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(
|
||||
uuid)
|
||||
|| receiver.hasPermission("chat.ignorebypass"));
|
||||
}
|
||||
Set<Player> receivers = stream.collect(Collectors.toSet());
|
||||
@@ -135,8 +144,13 @@ public class ChatListener implements Listener {
|
||||
for (Player pingPlayer : playersToPing) {
|
||||
pingPlayer.playSound(pingPlayer.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1);
|
||||
}
|
||||
chatLogHandler.addChatLog(uuid, ServerName.getServerName(), modifiableString.string(), false);
|
||||
ALogger.info(PlainTextComponentSerializer.plainText().serialize(input.asComponent()));
|
||||
chatLogHandler.addChatLog(uuid,
|
||||
ServerName.getServerName(),
|
||||
modifiableString.string(),
|
||||
modifiableString.component(),
|
||||
false
|
||||
);
|
||||
ALogger.info(PlainTextComponentSerializer.plainText().serialize(inputComponent));
|
||||
}
|
||||
|
||||
private void pingPlayers(Set<Player> playersToPing, ModifiableString modifiableString, Player player) {
|
||||
@@ -152,10 +166,10 @@ public class ChatListener implements Listener {
|
||||
ChatUser onlinePlayerUser = ChatUserManager.getChatUser(onlinePlayer.getUniqueId());
|
||||
if (namePattern.matcher(modifiableString.string()).find()) {
|
||||
modifiableString.replace(TextReplacementConfig.builder()
|
||||
.once()
|
||||
.match(namePattern)
|
||||
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
|
||||
.build());
|
||||
.once()
|
||||
.match(namePattern)
|
||||
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
|
||||
.build());
|
||||
//TODO replace all instances of \name with just name but using the match result so the capitalization doesn't change
|
||||
// modifiableString.replace(TextReplacementConfig.builder()
|
||||
// .once()
|
||||
@@ -171,10 +185,10 @@ public class ChatListener implements Listener {
|
||||
}
|
||||
} else if (nickPattern.matcher(modifiableString.string()).find()) {
|
||||
modifiableString.replace(TextReplacementConfig.builder()
|
||||
.once()
|
||||
.match(nickPattern)
|
||||
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
|
||||
.build());
|
||||
.once()
|
||||
.match(nickPattern)
|
||||
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
|
||||
.build());
|
||||
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId())
|
||||
|| player.hasPermission("chat.ignorebypass")) {
|
||||
playersToPing.add(onlinePlayer);
|
||||
@@ -192,7 +206,7 @@ public class ChatListener implements Listener {
|
||||
Placeholder.component("prefixall", user.getPrefixAll()),
|
||||
Placeholder.component("staffprefix", user.getStaffPrefix()),
|
||||
Placeholder.component("message", message)
|
||||
);
|
||||
);
|
||||
|
||||
return Utility.parseMiniMessage(Config.CHATFORMAT, placeholders);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user