Tweaked mails, added notifs, added config options
This commit is contained in:
parent
c18ffb9578
commit
a5d5d8d985
|
|
@ -4,6 +4,7 @@ import com.alttd.chat.objects.channels.CustomChannel;
|
|||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.Lists;
|
||||
import io.leangen.geantyref.TypeToken;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
import org.spongepowered.configurate.yaml.NodeStyle;
|
||||
|
|
@ -389,15 +390,19 @@ public final class Config {
|
|||
}
|
||||
|
||||
public static String mailHeader = "===== List Mails ====='";
|
||||
public static String mailBody = "<white>From:</white> <staffprefix><sender> <white>on:<date></white>\n<message>";
|
||||
public static String mailBody = "<white>From:</white> [<staffprefix>] <sender> <white><hover:show_text:'<date>'><time_ago> day(s) ago</hover>: </white><message>";
|
||||
public static String mailFooter = "======================";
|
||||
public static String mailNoUser = "<red>A player with this name hasn't logged in recently.";
|
||||
public static String mailReceived = "<yellow><click:run_command:/mail list unread>New mail from <sender>, click to view</click></yellow>";
|
||||
public static String mailUnread = "<green><click:run_command:/mail list unread>You have <amount> unread mail, click to view it.</click></green>";
|
||||
public static List<String> mailCommandAlias = new ArrayList<>();
|
||||
private static void mailSettings() {
|
||||
mailHeader = getString("settings.mail.header", mailHeader);
|
||||
mailBody = getString("settings.mail.message", mailBody);
|
||||
mailFooter = getString("settings.mail.footer", mailFooter);
|
||||
mailCommandAlias = getList("settings.mail.command-aliases", Lists.newArrayList("gmail"));
|
||||
mailReceived = getString("settings.mail.mail-received", mailReceived);
|
||||
mailUnread = getString("settings.mail.mail-unread", mailUnread);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ChatHandler {
|
||||
|
||||
|
|
@ -215,7 +216,9 @@ public class ChatHandler {
|
|||
chatUser.addMail(mail);
|
||||
// TODO load from config
|
||||
String finalSenderName = senderName;
|
||||
optionalPlayer.ifPresent(player -> player.sendMessage(Utility.parseMiniMessage("<yellow>New mail from " + finalSenderName)));
|
||||
optionalPlayer.ifPresent(player -> player.sendMessage(Utility.parseMiniMessage(Config.mailReceived, List.of(
|
||||
Template.template("sender", finalSenderName))
|
||||
)));
|
||||
}
|
||||
|
||||
public void readMail(CommandSource commandSource, String targetPlayer) {
|
||||
|
|
@ -243,11 +246,13 @@ public class ChatHandler {
|
|||
Queries.markMailRead(mail);
|
||||
}
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(mail.getSender());
|
||||
Date sentTime = new Date(mail.getSendTime());
|
||||
List<Template> templates = new ArrayList<>(List.of(
|
||||
Template.template("staffprefix", chatUser.getStaffPrefix()),
|
||||
Template.template("sender", chatUser.getDisplayName()),
|
||||
Template.template("message", mail.getMessage()),
|
||||
Template.template("date", new Date(mail.getSendTime()).toString())
|
||||
Template.template("date", sentTime.toString()),
|
||||
Template.template("time_ago", String.valueOf(TimeUnit.MILLISECONDS.toDays(new Date().getTime() - sentTime.getTime())))
|
||||
));
|
||||
Component mailMessage = Utility.parseMiniMessage(Config.mailBody, templates);
|
||||
component = component.append(Component.newline()).append(mailMessage);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.alttd.velocitychat.listeners;
|
|||
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.Mail;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.alttd.velocitychat.VelocityChat;
|
||||
import com.alttd.chat.config.Config;
|
||||
|
|
@ -14,6 +15,7 @@ import com.velocitypowered.api.event.Subscribe;
|
|||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||
import com.velocitypowered.api.event.connection.LoginEvent;
|
||||
import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
||||
import com.velocitypowered.api.event.player.ServerPostConnectEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
|
@ -44,6 +46,20 @@ public class ProxyPlayerListener {
|
|||
ServerHandler.addPlayerUUID(player.getUsername(), uuid);
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.LAST)
|
||||
public void afterPlayerLogin(ServerPostConnectEvent event) {
|
||||
if (event.getPreviousServer() != null)
|
||||
return;
|
||||
Player player = event.getPlayer();
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
List<Mail> unReadMail = chatUser.getUnReadMail();
|
||||
if (unReadMail.isEmpty())
|
||||
return;
|
||||
player.sendMessage(Utility.parseMiniMessage(Config.mailUnread, List.of(
|
||||
Template.template("amount", String.valueOf(unReadMail.size()))
|
||||
)));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void quitEvent(DisconnectEvent event) {
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user