mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-24 06:50:36 +00:00
Improvements and send all mail fix
Mail ID no longer exists and is handled by it's position in the mail array
This commit is contained in:
parent
ae190f3fa0
commit
7015905991
@ -80,9 +80,8 @@ public class SendMailCommand implements CommandHandler {
|
|||||||
Grasscutter.getGameServer().getPlayerByUid(mailBuilder.recipient, true).sendMail(mailBuilder.mail);
|
Grasscutter.getGameServer().getPlayerByUid(mailBuilder.recipient, true).sendMail(mailBuilder.mail);
|
||||||
CommandHandler.sendMessage(sender, "Message sent to user " + mailBuilder.recipient + "!");
|
CommandHandler.sendMessage(sender, "Message sent to user " + mailBuilder.recipient + "!");
|
||||||
} else {
|
} else {
|
||||||
// TODO: More testing required. This probably won't work for online players if DatabaseHelper.getPlayerById(string) didn't work.
|
|
||||||
for (GenshinPlayer player : DatabaseHelper.getAllPlayers()) {
|
for (GenshinPlayer player : DatabaseHelper.getAllPlayers()) {
|
||||||
player.sendMail(mailBuilder.mail);
|
Grasscutter.getGameServer().getPlayerByUid(player.getUid(), true).sendMail(mailBuilder.mail);
|
||||||
}
|
}
|
||||||
CommandHandler.sendMessage(sender, "Message sent to all users!");
|
CommandHandler.sendMessage(sender, "Message sent to all users!");
|
||||||
}
|
}
|
||||||
|
@ -604,20 +604,20 @@ public class GenshinPlayer {
|
|||||||
public List<Mail> getAllMail() { return this.mail; }
|
public List<Mail> getAllMail() { return this.mail; }
|
||||||
|
|
||||||
public void sendMail(Mail message) {
|
public void sendMail(Mail message) {
|
||||||
message._id = this.mail.size() + 1;
|
|
||||||
this.mail.add(message);
|
this.mail.add(message);
|
||||||
this.save();
|
this.save();
|
||||||
Grasscutter.getLogger().info("Message sent to user [" + this.getUid() + ":" + this.getNickname() + "]!");
|
Grasscutter.getLogger().info("Mail sent to user [" + this.getUid() + ":" + this.getNickname() + "]!");
|
||||||
if(this.getSession() != null) {
|
if(this.isOnline()) {
|
||||||
|
Grasscutter.getLogger().info("user online.");
|
||||||
this.sendPacket(new PacketMailChangeNotify(this, message));
|
this.sendPacket(new PacketMailChangeNotify(this, message));
|
||||||
} // TODO: setup a way for the mail notification to show up when someone receives mail when they were offline
|
} // TODO: setup a way for the mail notification to show up when someone receives mail when they were offline
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean deleteMail(int mailId) {
|
public boolean deleteMail(int mailId) {
|
||||||
Mail message = getMailById(mailId);
|
Mail message = getMail(mailId);
|
||||||
|
|
||||||
if(message != null) {
|
if(message != null) {
|
||||||
int index = getMailIndex(message);
|
int index = getMailId(message);
|
||||||
message.expireTime = (int) Instant.now().getEpochSecond(); // Just set the mail as expired for now. I don't want to implement a counter specifically for an account...
|
message.expireTime = (int) Instant.now().getEpochSecond(); // Just set the mail as expired for now. I don't want to implement a counter specifically for an account...
|
||||||
this.replaceMailByIndex(index, message);
|
this.replaceMailByIndex(index, message);
|
||||||
return true;
|
return true;
|
||||||
@ -626,16 +626,13 @@ public class GenshinPlayer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mail getMailById(int mailId) {
|
public Mail getMail(int index) { return this.mail.get(index); }
|
||||||
return this.mail.stream().filter(message -> message._id == mailId).findFirst().orElse(null);
|
public int getMailId(Mail message) {
|
||||||
}
|
|
||||||
|
|
||||||
public int getMailIndex(Mail message) {
|
|
||||||
return this.mail.indexOf(message);
|
return this.mail.indexOf(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean replaceMailByIndex(int index, Mail message) {
|
public boolean replaceMailByIndex(int index, Mail message) {
|
||||||
if(getMailById(index) != null) {
|
if(getMail(index) != null) {
|
||||||
this.mail.set(index, message);
|
this.mail.set(index, message);
|
||||||
this.save();
|
this.save();
|
||||||
return true;
|
return true;
|
||||||
|
@ -9,7 +9,6 @@ import java.util.List;
|
|||||||
@Entity
|
@Entity
|
||||||
public class Mail {
|
public class Mail {
|
||||||
|
|
||||||
public int _id;
|
|
||||||
public MailContent mailContent;
|
public MailContent mailContent;
|
||||||
public List<MailItem> itemList;
|
public List<MailItem> itemList;
|
||||||
public long sendTime;
|
public long sendTime;
|
||||||
@ -32,11 +31,6 @@ public class Mail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Mail(MailContent mailContent, List<MailItem> itemList, long expireTime, int importance, int state) {
|
public Mail(MailContent mailContent, List<MailItem> itemList, long expireTime, int importance, int state) {
|
||||||
this(0, mailContent, itemList, expireTime, importance, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mail(int _id, MailContent mailContent, List<MailItem> itemList, long expireTime, int importance, int state) {
|
|
||||||
this._id = _id;
|
|
||||||
this.mailContent = mailContent;
|
this.mailContent = mailContent;
|
||||||
this.itemList = itemList;
|
this.itemList = itemList;
|
||||||
this.sendTime = (int) Instant.now().getEpochSecond();
|
this.sendTime = (int) Instant.now().getEpochSecond();
|
||||||
@ -47,10 +41,6 @@ public class Mail {
|
|||||||
this.stateValue = state; // Different mailboxes, 1 = Default, 3 = Gift-box.
|
this.stateValue = state; // Different mailboxes, 1 = Default, 3 = Gift-box.
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return this._id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public static class MailContent {
|
public static class MailContent {
|
||||||
public String title;
|
public String title;
|
||||||
|
@ -21,12 +21,11 @@ public class HandlerChangeMailStarNotify extends PacketHandler {
|
|||||||
List<Mail> updatedMail = new ArrayList<>();
|
List<Mail> updatedMail = new ArrayList<>();
|
||||||
|
|
||||||
for (int mailId : req.getMailIdListList()) {
|
for (int mailId : req.getMailIdListList()) {
|
||||||
Mail message = session.getPlayer().getMailById(mailId);
|
Mail message = session.getPlayer().getMail(mailId);
|
||||||
int messageIndex = session.getPlayer().getMailIndex(message);
|
|
||||||
|
|
||||||
message.importance = req.getIsStar() == true ? 1 : 0;
|
message.importance = req.getIsStar() == true ? 1 : 0;
|
||||||
|
|
||||||
session.getPlayer().replaceMailByIndex(messageIndex, message);
|
session.getPlayer().replaceMailByIndex(mailId, message);
|
||||||
updatedMail.add(message);
|
updatedMail.add(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,12 +22,11 @@ public class HandlerReadMailNotify extends PacketHandler {
|
|||||||
List<Mail> updatedMail = new ArrayList<>();
|
List<Mail> updatedMail = new ArrayList<>();
|
||||||
|
|
||||||
for (int mailId : req.getMailIdListList()) {
|
for (int mailId : req.getMailIdListList()) {
|
||||||
Mail message = session.getPlayer().getMailById(mailId);
|
Mail message = session.getPlayer().getMail(mailId);
|
||||||
int messageIndex = session.getPlayer().getMailIndex(message);
|
|
||||||
|
|
||||||
message.isRead = true;
|
message.isRead = true;
|
||||||
|
|
||||||
session.getPlayer().replaceMailByIndex(messageIndex, message);
|
session.getPlayer().replaceMailByIndex(mailId, message);
|
||||||
updatedMail.add(message);
|
updatedMail.add(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public class PacketGetAllMailRsp extends GenshinPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MailDataOuterClass.MailData.Builder mailData = MailDataOuterClass.MailData.newBuilder();
|
MailDataOuterClass.MailData.Builder mailData = MailDataOuterClass.MailData.newBuilder();
|
||||||
mailData.setMailId(message._id);
|
mailData.setMailId(player.getMailId(message));
|
||||||
mailData.setMailTextContent(mailTextContent.build());
|
mailData.setMailTextContent(mailTextContent.build());
|
||||||
mailData.addAllItemList(mailItems);
|
mailData.addAllItemList(mailItems);
|
||||||
mailData.setSendTime((int) message.sendTime);
|
mailData.setSendTime((int) message.sendTime);
|
||||||
|
@ -25,8 +25,7 @@ public class PacketGetMailItemRsp extends GenshinPacket {
|
|||||||
GetMailItemRsp.Builder proto = GetMailItemRsp.newBuilder();
|
GetMailItemRsp.Builder proto = GetMailItemRsp.newBuilder();
|
||||||
|
|
||||||
for (int mailId : mailList) {
|
for (int mailId : mailList) {
|
||||||
Mail message = player.getMailById(mailId);
|
Mail message = player.getMail(mailId);
|
||||||
int messageIndex = player.getMailIndex(message);
|
|
||||||
|
|
||||||
for(Mail.MailItem mailItem : message.itemList) {
|
for(Mail.MailItem mailItem : message.itemList) {
|
||||||
EquipParamOuterClass.EquipParam.Builder item = EquipParamOuterClass.EquipParam.newBuilder();
|
EquipParamOuterClass.EquipParam.Builder item = EquipParamOuterClass.EquipParam.newBuilder();
|
||||||
@ -62,10 +61,10 @@ public class PacketGetMailItemRsp extends GenshinPacket {
|
|||||||
message.isAttachmentGot = true;
|
message.isAttachmentGot = true;
|
||||||
claimedMessages.add(message);
|
claimedMessages.add(message);
|
||||||
|
|
||||||
player.replaceMailByIndex(messageIndex, message);
|
player.replaceMailByIndex(mailId, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
proto.addAllMailIdList(claimedMessages.stream().map(Mail::getId).collect(Collectors.toList()));
|
proto.addAllMailIdList(claimedMessages.stream().map(message -> player.getMailId(message)).collect(Collectors.toList()));
|
||||||
proto.addAllItemList(claimedItems);
|
proto.addAllItemList(claimedItems);
|
||||||
|
|
||||||
this.setData(proto.build());
|
this.setData(proto.build());
|
||||||
|
@ -46,7 +46,7 @@ public class PacketMailChangeNotify extends GenshinPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MailDataOuterClass.MailData.Builder mailData = MailDataOuterClass.MailData.newBuilder();
|
MailDataOuterClass.MailData.Builder mailData = MailDataOuterClass.MailData.newBuilder();
|
||||||
mailData.setMailId(message._id);
|
mailData.setMailId(player.getMailId(message));
|
||||||
mailData.setMailTextContent(mailTextContent.build());
|
mailData.setMailTextContent(mailTextContent.build());
|
||||||
mailData.addAllItemList(mailItems);
|
mailData.addAllItemList(mailItems);
|
||||||
mailData.setSendTime((int) message.sendTime);
|
mailData.setSendTime((int) message.sendTime);
|
||||||
|
Loading…
Reference in New Issue
Block a user