private void OnModMessageReceived(object?sender, ModMessageReceivedEventArgs e) { if (e.FromModID != ModManifest.UniqueID) { return; } if (e.Type == MailListMessage) { Mails.Clear(); var serializedMails = e.ReadAs <List <MailData <string> > >(); foreach (var serializedMail in serializedMails) { Mails.Add(serializedMail.Deserialize()); } UpdateMails(); } else if (e.Type == NewMailMessage) { var serializedMail = e.ReadAs <MailData <string> >(); Mails.Add(serializedMail.Deserialize()); if (GameExt.GetMultiplayerMode() == MultiplayerMode.Server) { Helper.Multiplayer.SendMessage( serializedMail, NewMailMessage, new[] { ModManifest.UniqueID }, Game1.getOnlineFarmers() .Select(p => p.UniqueMultiplayerID) .Where(id => id != GameExt.GetHostPlayer().UniqueMultiplayerID&& id != e.FromPlayerID) .ToArray() ); } if (serializedMail.AddresseeID == Game1.player.UniqueMultiplayerID) { UpdateMails(); } } else if (e.Type == ReadMailMessage) { var(modUniqueID, mailID) = e.ReadAs <(string, string)>(); var mail = Mails.FirstOrDefault(m => m.ModUniqueID == modUniqueID && m.ID == mailID); if (mail is not null && mail.Title is null) { Mails.Remove(mail); if (GameExt.GetMultiplayerMode() == MultiplayerMode.Server) { Helper.Multiplayer.SendMessage( (modUniqueID, mailID), ReadMailMessage, new[] { ModManifest.UniqueID }, Game1.getOnlineFarmers() .Select(p => p.UniqueMultiplayerID) .Where(id => id != GameExt.GetHostPlayer().UniqueMultiplayerID&& id != e.FromPlayerID) .ToArray() ); } if (mail.AddresseeID == Game1.player.UniqueMultiplayerID) { UpdateMails(); } } } else { Monitor.Log($"Received unknown message of type {e.Type}.", LogLevel.Trace); } }