mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-22 20:04:56 +01:00
Simplify the mail handler
This commit is contained in:
@@ -1,22 +1,40 @@
|
||||
package emu.grasscutter.server.packet.send;
|
||||
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.net.packet.BasePacket;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.GetAllMailResultNotifyOuterClass;
|
||||
import emu.grasscutter.net.proto.MailDataOuterClass;
|
||||
import emu.grasscutter.net.proto.GetAllMailResultNotifyOuterClass.GetAllMailResultNotify;
|
||||
import emu.grasscutter.utils.Utils;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
public class PacketGetAllMailResultNotify extends BasePacket {
|
||||
public PacketGetAllMailResultNotify(int packetBeSentNum, int packetNum, List<MailDataOuterClass.MailData> mailData, String transaction, boolean isGift) {
|
||||
public final class PacketGetAllMailResultNotify extends BasePacket {
|
||||
/**
|
||||
* @param player The player to fetch the mail for.
|
||||
* @param gifts Is the mail for gifts?
|
||||
*/
|
||||
public PacketGetAllMailResultNotify(Player player, boolean gifts) {
|
||||
super(PacketOpcodes.GetAllMailResultNotify);
|
||||
|
||||
this.setData(GetAllMailResultNotifyOuterClass.GetAllMailResultNotify.newBuilder()
|
||||
.setPacketBeSentNum(packetBeSentNum)
|
||||
.addAllMailList(mailData)
|
||||
.setTransaction(transaction)
|
||||
.setIsCollected(isGift)
|
||||
.setPacketNum(packetNum)
|
||||
.build());
|
||||
var packet = GetAllMailResultNotify.newBuilder()
|
||||
.setTransaction(player.getUid() + "-" + Utils.getCurrentSeconds() + "-" + 0)
|
||||
.setIsCollected(gifts)
|
||||
.setPacketBeSentNum(1)
|
||||
.setPacketNum(1);
|
||||
|
||||
var inbox = player.getAllMail();
|
||||
if (!gifts && inbox.size() > 0) {
|
||||
packet.addAllMailList(inbox.stream()
|
||||
.filter(mail -> mail.stateValue == 1)
|
||||
.filter(mail -> mail.expireTime > Instant.now().getEpochSecond())
|
||||
.map(mail -> mail.toProto(player)).toList());
|
||||
} else {
|
||||
// Empty mailbox.
|
||||
// TODO: Implement the gift mailbox.
|
||||
packet.addAllMailList(List.of());
|
||||
}
|
||||
|
||||
this.setData(packet.build());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user