Integrate ChatLogHandler across chat modules and add centralized message logging with validation through ChatLogMapper.
This commit is contained in:
@@ -2,20 +2,20 @@ package com.alttd.velocitychat;
|
||||
|
||||
import com.alttd.chat.ChatAPI;
|
||||
import com.alttd.chat.ChatImplementation;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.DatabaseConnection;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.velocitychat.commands.*;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.DatabaseConnection;
|
||||
import com.alttd.velocitychat.handlers.ChatHandler;
|
||||
import com.alttd.velocitychat.handlers.ServerHandler;
|
||||
import com.alttd.velocitychat.listeners.ChatListener;
|
||||
import com.alttd.velocitychat.listeners.LiteBansListener;
|
||||
import com.alttd.velocitychat.listeners.ProxyPlayerListener;
|
||||
import com.alttd.velocitychat.listeners.PluginMessageListener;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.velocitychat.listeners.ProxyPlayerListener;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.inject.Inject;
|
||||
@@ -36,7 +36,7 @@ import java.nio.file.Path;
|
||||
description = "A chat plugin for Altitude Minecraft Server",
|
||||
authors = {"destro174", "teri"},
|
||||
dependencies = {@Dependency(id = "luckperms"), @Dependency(id = "litebans"), @Dependency(id = "proxydiscordlink")}
|
||||
)
|
||||
)
|
||||
public class VelocityChat {
|
||||
|
||||
private static VelocityChat plugin;
|
||||
@@ -67,7 +67,8 @@ public class VelocityChat {
|
||||
PartyManager.initialize(); // load the parties from the db and add the previously loaded users to them
|
||||
|
||||
serverHandler = new ServerHandler();
|
||||
chatHandler = new ChatHandler();
|
||||
ChatLogHandler chatLogHandler = new ChatLogHandler(true);
|
||||
chatHandler = new ChatHandler(chatLogHandler);
|
||||
server.getEventManager().register(this, new ChatListener());
|
||||
server.getEventManager().register(this, new ProxyPlayerListener());
|
||||
new LiteBansListener().init(); // init the litebans api listeners
|
||||
@@ -89,7 +90,11 @@ public class VelocityChat {
|
||||
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
||||
buf.writeUTF("reloadconfig");
|
||||
ALogger.info("Reloaded ChatPlugin proxy config.");
|
||||
getProxy().getAllServers().stream().forEach(registeredServer -> registeredServer.sendPluginMessage(getChannelIdentifier(), buf.toByteArray()));
|
||||
getProxy().getAllServers()
|
||||
.stream()
|
||||
.forEach(registeredServer -> registeredServer.sendPluginMessage(getChannelIdentifier(),
|
||||
buf.toByteArray()
|
||||
));
|
||||
}
|
||||
|
||||
public File getDataDirectory() {
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import com.alttd.chat.objects.*;
|
||||
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||
import com.alttd.chat.objects.chat_log.ChatLogType;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.alttd.velocitychat.VelocityChat;
|
||||
@@ -32,6 +34,12 @@ import java.util.UUID;
|
||||
|
||||
public class ChatHandler {
|
||||
|
||||
private final ChatLogHandler chatLogHandler;
|
||||
|
||||
public ChatHandler(ChatLogHandler chatLogHandler) {
|
||||
this.chatLogHandler = chatLogHandler;
|
||||
}
|
||||
|
||||
public void privateMessage(String sender, String target, String message) {
|
||||
UUID uuid = UUID.fromString(sender);
|
||||
ChatUser senderUser = ChatUserManager.getChatUser(uuid);
|
||||
@@ -54,15 +62,23 @@ public class ChatHandler {
|
||||
Placeholder.component("receiver", targetUser.getDisplayName()),
|
||||
Placeholder.unparsed("receivername", player2.getUsername()),
|
||||
Placeholder.component("message", GsonComponentSerializer.gson().deserialize(message)),
|
||||
Placeholder.unparsed("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude"));
|
||||
Placeholder.unparsed("server",
|
||||
player.getCurrentServer().isPresent() ? player.getCurrentServer()
|
||||
.get()
|
||||
.getServerInfo()
|
||||
.getName() : "Altitude"
|
||||
)
|
||||
);
|
||||
|
||||
ServerConnection serverConnection;
|
||||
//Log handled on receiving server since it is only received on one server and that's where the ignore check happens
|
||||
if (player.getCurrentServer().isPresent() && player2.getCurrentServer().isPresent()) {
|
||||
// redirect to the sender
|
||||
serverConnection = player.getCurrentServer().get();
|
||||
Component component = Utility.parseMiniMessage(Config.MESSAGESENDER
|
||||
.replaceAll("<sendername>", player.getUsername())
|
||||
.replaceAll("<receivername>", player2.getUsername()), Placeholders).asComponent();
|
||||
.replaceAll("<sendername>", player.getUsername())
|
||||
.replaceAll("<receivername>", player2.getUsername()), Placeholders
|
||||
).asComponent();
|
||||
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
||||
buf.writeUTF("privatemessageout");
|
||||
buf.writeUTF(player.getUniqueId().toString());
|
||||
@@ -74,8 +90,9 @@ public class ChatHandler {
|
||||
//redirect to the receiver
|
||||
serverConnection = player2.getCurrentServer().get();
|
||||
component = Utility.parseMiniMessage(Config.MESSAGERECIEVER
|
||||
.replaceAll("<sendername>", player.getUsername())
|
||||
.replaceAll("<receivername>", player2.getUsername()), Placeholders).asComponent();
|
||||
.replaceAll("<sendername>", player.getUsername())
|
||||
.replaceAll("<receivername>", player2.getUsername()), Placeholders
|
||||
).asComponent();
|
||||
buf = ByteStreams.newDataOutput();
|
||||
buf.writeUTF("privatemessagein");
|
||||
buf.writeUTF(player2.getUniqueId().toString());
|
||||
@@ -93,7 +110,7 @@ public class ChatHandler {
|
||||
Placeholder.parsed("displayname", Utility.getDisplayName(player.getUniqueId(), player.getUsername())),
|
||||
Placeholder.unparsed("target", (target.isEmpty() ? " tried to say: " : " -> " + target + ": ")),
|
||||
Placeholder.unparsed("input", input)
|
||||
);
|
||||
);
|
||||
ComponentLike blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, Placeholders);
|
||||
|
||||
serverConnection.getServer().getPlayersConnected().forEach(pl -> {
|
||||
@@ -134,15 +151,15 @@ public class ChatHandler {
|
||||
}
|
||||
ComponentLike senderName = user.getDisplayName();
|
||||
|
||||
TagResolver Placeholders = TagResolver.resolver(
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("sender", senderName),
|
||||
Placeholder.component("sendername", senderName),
|
||||
Placeholder.unparsed("partyname", party.getPartyName()),
|
||||
Placeholder.component("message", parseMessageContent(player, message)),
|
||||
Placeholder.unparsed("server", serverConnection.getServer().getServerInfo().getName())
|
||||
);
|
||||
);
|
||||
|
||||
Component partyMessage = Utility.parseMiniMessage(Config.PARTY_FORMAT, Placeholders).asComponent()
|
||||
Component partyMessage = Utility.parseMiniMessage(Config.PARTY_FORMAT, placeholders).asComponent()
|
||||
.replaceText(TextReplacementConfig.builder().once().matchLiteral("[i]").replacement(item).build());
|
||||
|
||||
ModifiableString modifiableString = new ModifiableString(partyMessage);
|
||||
@@ -155,7 +172,17 @@ public class ChatHandler {
|
||||
|
||||
sendPartyMessage(party, partyMessage, user.getIgnoredBy());
|
||||
|
||||
ComponentLike spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, Placeholders);
|
||||
chatLogHandler.addChatLog(uuid,
|
||||
serverConnection.getServer().getServerInfo().getName(),
|
||||
PlainTextComponentSerializer.plainText().serialize(partyMessage),
|
||||
ChatLogType.PARTY,
|
||||
String.valueOf(party.getPartyId()),
|
||||
null,
|
||||
partyMessage,
|
||||
false
|
||||
);
|
||||
|
||||
ComponentLike spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, placeholders);
|
||||
for (Player pl : serverConnection.getServer().getPlayersConnected()) {
|
||||
if (pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) {
|
||||
pl.sendMessage(spyMessage);
|
||||
@@ -171,6 +198,17 @@ public class ChatHandler {
|
||||
.stream()
|
||||
.filter(target -> target.hasPermission("command.chat.globaladminchat"))
|
||||
.forEach(target -> target.sendMessage(component));
|
||||
|
||||
chatLogHandler.addChatLog(
|
||||
new UUID(0, 0), //No origin uuid for GAC
|
||||
"GAC", //No server for GAC
|
||||
PlainTextComponentSerializer.plainText().serialize(component),
|
||||
ChatLogType.GAC,
|
||||
null,
|
||||
null,
|
||||
component,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
public void globalAdminChat(CommandSource commandSource, String message) {
|
||||
@@ -182,13 +220,17 @@ public class ChatHandler {
|
||||
return;
|
||||
}
|
||||
senderName = user.getDisplayName();
|
||||
serverName = sender.getCurrentServer().isPresent() ? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude";
|
||||
serverName = sender.getCurrentServer().isPresent() ? sender.getCurrentServer()
|
||||
.get()
|
||||
.getServerInfo()
|
||||
.getName() : "Altitude";
|
||||
}
|
||||
|
||||
TagResolver Placeholders = TagResolver.resolver(
|
||||
Placeholder.component("message", parseMessageContent(commandSource, message)),
|
||||
Placeholder.component("sender", senderName),
|
||||
Placeholder.unparsed("server", serverName));
|
||||
Placeholder.unparsed("server", serverName)
|
||||
);
|
||||
|
||||
ComponentLike component = Utility.parseMiniMessage(Config.GACFORMAT, Placeholders);
|
||||
|
||||
@@ -210,7 +252,8 @@ public class ChatHandler {
|
||||
if (optionalPlayer.isEmpty()) {
|
||||
targetUUID = ServerHandler.getPlayerUUID(recipient);
|
||||
if (targetUUID == null) {
|
||||
commandSource.sendMessage(Utility.parseMiniMessage("<red>A player with this name hasn't logged in recently.")); // TOOD load from config
|
||||
commandSource.sendMessage(Utility.parseMiniMessage(
|
||||
"<red>A player with this name hasn't logged in recently.")); // TOOD load from config
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -274,8 +317,10 @@ public class ChatHandler {
|
||||
Placeholder.component("sender", chatUser.getDisplayName()),
|
||||
Placeholder.component("message", Utility.parseMiniMessage(mail.getMessage())),
|
||||
Placeholder.unparsed("date", date.toString()),
|
||||
Placeholder.unparsed("time_ago", getTimeAgo(Duration.between(date.toInstant(), new Date().toInstant())))
|
||||
);
|
||||
Placeholder.unparsed("time_ago",
|
||||
getTimeAgo(Duration.between(date.toInstant(), new Date().toInstant()))
|
||||
)
|
||||
);
|
||||
ComponentLike mailMessage = Utility.parseMiniMessage(Config.mailBody, Placeholders);
|
||||
component = component.append(Component.newline()).append(mailMessage);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user