finish mails?

This commit is contained in:
destro174
2022-01-29 23:21:35 +01:00
parent 26b044b2e7
commit 57a43e9c1c
8 changed files with 111 additions and 44 deletions
@@ -2,7 +2,11 @@ package com.alttd.velocitychat;
import com.alttd.chat.ChatAPI;
import com.alttd.chat.ChatImplementation;
import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.util.Utility;
import com.alttd.velocitychat.commands.GlobalAdminChat;
import com.alttd.velocitychat.commands.MailCommand;
import com.alttd.velocitychat.commands.Reload;
import com.alttd.chat.config.Config;
import com.alttd.chat.database.DatabaseConnection;
@@ -71,8 +75,11 @@ public class VelocityChat {
channelIdentifier = MinecraftChannelIdentifier.create(channels[0], channels[1]);
server.getChannelRegistrar().register(channelIdentifier);
server.getEventManager().register(this, new PluginMessageListener(channelIdentifier));
loadCommands();
// setup console chatuser
ChatUser console = new ChatUser(Config.CONSOLEUUID, -1, null);
console.setDisplayName(Config.CONSOLENAME);
ChatUserManager.addUser(console);
}
public void ReloadConfig() {
@@ -104,6 +111,7 @@ public class VelocityChat {
public void loadCommands() {
new GlobalAdminChat(server);
new Reload(server);
new MailCommand(server);
// all (proxy)commands go here
}
@@ -1,5 +1,6 @@
package com.alttd.velocitychat.commands;
import com.alttd.chat.config.Config;
import com.alttd.velocitychat.VelocityChat;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
@@ -77,20 +78,9 @@ public class MailCommand {
})
)
.then(playerNode
.then(LiteralArgumentBuilder.<CommandSource>literal("unread")
.executes(context -> {
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), context.getArgument("player", String.class), true);
return 1;
})
)
.then(LiteralArgumentBuilder.<CommandSource>literal("all")
.executes(context -> {
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), context.getArgument("player", String.class), false);
return 1;
})
)
.requires(ctx -> ctx.hasPermission("command.chat.mail.list.other"))// TODO permission
.executes(context -> {
sendHelpMessage(context.getSource());
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), context.getArgument("player", String.class));
return 1;
})
)
@@ -113,9 +103,9 @@ public class MailCommand {
CommandMeta.Builder metaBuilder = proxyServer.getCommandManager().metaBuilder(brigadierCommand);
/*for (String alias : Config.MAILCOMMANDALIASES) {
for (String alias : Config.mailCommandAlias) {
metaBuilder.aliases(alias);
}*/
}
CommandMeta meta = metaBuilder.build();
@@ -1,6 +1,7 @@
package com.alttd.velocitychat.handlers;
import com.alttd.chat.config.Config;
import com.alttd.chat.database.Queries;
import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.PartyManager;
import com.alttd.chat.objects.ChatUser;
@@ -139,37 +140,41 @@ public class ChatHandler {
optionalPlayer.ifPresent(player -> player.sendMessage(Utility.parseMiniMessage("<yellow>New mail from " + finalSenderName)));
}
public void readMail(CommandSource commandSource, String targetPlayer, boolean unread) {
public void readMail(CommandSource commandSource, String targetPlayer) {
UUID uuid = ServerHandler.getPlayerUUID(targetPlayer);
if (uuid == null) {
commandSource.sendMessage(Utility.parseMiniMessage("<red>A player with this name hasn't logged in recently.")); // TOOD load from config
commandSource.sendMessage(Utility.parseMiniMessage(Config.mailNoUser));
return;
}
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
commandSource.sendMessage(getMails(chatUser.getMails(), false));
commandSource.sendMessage(parseMails(chatUser.getMails(), false));
}
public void readMail(CommandSource commandSource, boolean unread) {
if (commandSource instanceof Player player) {
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
commandSource.sendMessage(getMails(chatUser.getMails(), unread));
commandSource.sendMessage(parseMails(unread ? chatUser.getUnReadMail() : chatUser.getMails(), unread));
}
}
private Component getMails(List<Mail> mails, boolean mark) {
Component component = Component.empty();
private Component parseMails(List<Mail> mails, boolean mark) {
Component component = Utility.parseMiniMessage(Config.mailHeader);
for (Mail mail : mails) {
if (mail.isUnRead() && mark) mail.setReadTime(System.currentTimeMillis());
if (mail.isUnRead() && mark) {
mail.setReadTime(System.currentTimeMillis());
Queries.markMailRead(mail);
}
ChatUser chatUser = ChatUserManager.getChatUser(mail.getSender());
List<Template> templates = new ArrayList<>(List.of(
Template.template("staffprefix", chatUser.getStaffPrefix()),
Template.template("name", chatUser.getDisplayName()),
Template.template("message", "<pre>" + mail.getMessage() + "<pre>"),
Template.template("sendtime", new Date(mail.getSendTime()).toString())
Template.template("sender", chatUser.getDisplayName()),
Template.template("message", mail.getMessage()),
Template.template("date", new Date(mail.getSendTime()).toString())
));
Component mailMessage = Utility.parseMiniMessage("", templates);
Component mailMessage = Utility.parseMiniMessage(Config.mailBody, templates);
component = component.append(Component.newline()).append(mailMessage);
}
component = component.append(Component.newline()).append(Utility.parseMiniMessage(Config.mailFooter));
return component;
}