mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-14 14:24:37 +01:00
Fix delete/claim all buttons in mail box
This commit is contained in:
@@ -1,8 +1,13 @@
|
|||||||
package emu.lunarcore.command.commands;
|
package emu.lunarcore.command.commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.bwaldvogel.mongo.backend.Utils;
|
||||||
import emu.lunarcore.command.Command;
|
import emu.lunarcore.command.Command;
|
||||||
import emu.lunarcore.command.CommandArgs;
|
import emu.lunarcore.command.CommandArgs;
|
||||||
import emu.lunarcore.command.CommandHandler;
|
import emu.lunarcore.command.CommandHandler;
|
||||||
|
import emu.lunarcore.game.inventory.GameItem;
|
||||||
import emu.lunarcore.game.mail.Mail;
|
import emu.lunarcore.game.mail.Mail;
|
||||||
import emu.lunarcore.game.player.Player;
|
import emu.lunarcore.game.player.Player;
|
||||||
|
|
||||||
@@ -17,9 +22,38 @@ public class MailCommand implements CommandHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get attachments
|
||||||
|
List<GameItem> attachments = new ArrayList<>();
|
||||||
|
|
||||||
|
var it = args.getList().iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
try {
|
||||||
|
String str = it.next();
|
||||||
|
|
||||||
|
if (str.contains(":")) {
|
||||||
|
String[] split = str.split(":");
|
||||||
|
|
||||||
|
int itemId = Integer.parseInt(split[0]);
|
||||||
|
int count = Integer.parseInt(split[1]);
|
||||||
|
|
||||||
|
attachments.add(new GameItem(itemId, count));
|
||||||
|
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build mail
|
||||||
String content = String.join(" ", args.getList());
|
String content = String.join(" ", args.getList());
|
||||||
Mail mail = new Mail("Test", "System Mail", content);
|
Mail mail = new Mail("Test", "System Mail", content);
|
||||||
|
|
||||||
|
for (GameItem item : attachments) {
|
||||||
|
mail.addAttachment(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send to target
|
||||||
args.getTarget().getMailbox().sendMail(mail);
|
args.getTarget().getMailbox().sendMail(mail);
|
||||||
|
|
||||||
sender.sendMessage("Sending mail to " + args.getTarget().getName());
|
sender.sendMessage("Sending mail to " + args.getTarget().getName());
|
||||||
|
|||||||
@@ -60,10 +60,15 @@ public class Mailbox extends BasePlayerManager implements Iterable<Mail> {
|
|||||||
this.getPlayer().sendPacket(new PacketNewMailScNotify(mail));
|
this.getPlayer().sendPacket(new PacketNewMailScNotify(mail));
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized List<GameItem> takeMailAttachments(RepeatedInt idList) {
|
public synchronized List<Mail> takeMailAttachments(RepeatedInt idList) {
|
||||||
List<GameItem> attachments = new ArrayList<>();
|
List<Mail> attachments = new ArrayList<>();
|
||||||
|
|
||||||
|
if (idList.length() == 0) {
|
||||||
|
this.getMap().keySet().forEach(idList::add);
|
||||||
|
}
|
||||||
|
|
||||||
for (int id : idList) {
|
for (int id : idList) {
|
||||||
|
// Get mail from hash map
|
||||||
Mail mail = getMap().get(id);
|
Mail mail = getMap().get(id);
|
||||||
if (mail == null || mail.isRead() || mail.getAttachments() == null) {
|
if (mail == null || mail.isRead() || mail.getAttachments() == null) {
|
||||||
continue;
|
continue;
|
||||||
@@ -72,11 +77,13 @@ public class Mailbox extends BasePlayerManager implements Iterable<Mail> {
|
|||||||
// Add attachments to inventory
|
// Add attachments to inventory
|
||||||
for (GameItem item : mail.getAttachments()) {
|
for (GameItem item : mail.getAttachments()) {
|
||||||
getPlayer().getInventory().addItem(item);
|
getPlayer().getInventory().addItem(item);
|
||||||
attachments.add(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set read
|
// Set read
|
||||||
mail.setRead();
|
mail.setRead();
|
||||||
|
|
||||||
|
//
|
||||||
|
attachments.add(mail);
|
||||||
}
|
}
|
||||||
|
|
||||||
return attachments;
|
return attachments;
|
||||||
@@ -85,14 +92,25 @@ public class Mailbox extends BasePlayerManager implements Iterable<Mail> {
|
|||||||
public synchronized IntList deleteMail(RepeatedInt idList) {
|
public synchronized IntList deleteMail(RepeatedInt idList) {
|
||||||
IntList deleteList = new IntArrayList();
|
IntList deleteList = new IntArrayList();
|
||||||
|
|
||||||
|
if (idList.length() == 0) {
|
||||||
|
this.getMap().keySet().forEach(idList::add);
|
||||||
|
}
|
||||||
|
|
||||||
for (int id : idList) {
|
for (int id : idList) {
|
||||||
Mail mail = getMap().remove(id);
|
// Get mail from hash map
|
||||||
if (mail != null) {
|
Mail mail = getMap().get(id);
|
||||||
// Delete from database
|
if (mail == null || !mail.isRead()) {
|
||||||
mail.delete();
|
continue;
|
||||||
// Add to delete result list
|
|
||||||
deleteList.add(mail.getUniqueId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove
|
||||||
|
getMap().remove(id);
|
||||||
|
|
||||||
|
// Delete from database
|
||||||
|
mail.delete();
|
||||||
|
|
||||||
|
// Add to delete result list
|
||||||
|
deleteList.add(mail.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
return deleteList;
|
return deleteList;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package emu.lunarcore.server.packet.recv;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import emu.lunarcore.game.inventory.GameItem;
|
import emu.lunarcore.game.mail.Mail;
|
||||||
import emu.lunarcore.proto.TakeMailAttachmentCsReqOuterClass.TakeMailAttachmentCsReq;
|
import emu.lunarcore.proto.TakeMailAttachmentCsReqOuterClass.TakeMailAttachmentCsReq;
|
||||||
import emu.lunarcore.server.game.GameSession;
|
import emu.lunarcore.server.game.GameSession;
|
||||||
import emu.lunarcore.server.packet.CmdId;
|
import emu.lunarcore.server.packet.CmdId;
|
||||||
@@ -17,9 +17,9 @@ public class HandlerTakeMailAttachmentCsReq extends PacketHandler {
|
|||||||
public void handle(GameSession session, byte[] header, byte[] data) throws Exception {
|
public void handle(GameSession session, byte[] header, byte[] data) throws Exception {
|
||||||
var req = TakeMailAttachmentCsReq.parseFrom(data);
|
var req = TakeMailAttachmentCsReq.parseFrom(data);
|
||||||
|
|
||||||
List<GameItem> attachments = session.getPlayer().getMailbox().takeMailAttachments(req.getMailIdList());
|
List<Mail> attachments = session.getPlayer().getMailbox().takeMailAttachments(req.getMailIdList());
|
||||||
|
|
||||||
session.send(new PacketTakeMailAttachmentScRsp(req.getMailIdList(), attachments));
|
session.send(new PacketTakeMailAttachmentScRsp(attachments));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,24 +3,26 @@ package emu.lunarcore.server.packet.send;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import emu.lunarcore.game.inventory.GameItem;
|
import emu.lunarcore.game.inventory.GameItem;
|
||||||
|
import emu.lunarcore.game.mail.Mail;
|
||||||
import emu.lunarcore.proto.TakeMailAttachmentScRspOuterClass.TakeMailAttachmentScRsp;
|
import emu.lunarcore.proto.TakeMailAttachmentScRspOuterClass.TakeMailAttachmentScRsp;
|
||||||
import emu.lunarcore.server.packet.BasePacket;
|
import emu.lunarcore.server.packet.BasePacket;
|
||||||
import emu.lunarcore.server.packet.CmdId;
|
import emu.lunarcore.server.packet.CmdId;
|
||||||
import us.hebi.quickbuf.RepeatedInt;
|
|
||||||
|
|
||||||
public class PacketTakeMailAttachmentScRsp extends BasePacket {
|
public class PacketTakeMailAttachmentScRsp extends BasePacket {
|
||||||
|
|
||||||
public PacketTakeMailAttachmentScRsp(RepeatedInt idList, Collection<GameItem> items) {
|
public PacketTakeMailAttachmentScRsp(Collection<Mail> mailList) {
|
||||||
super(CmdId.TakeMailAttachmentScRsp);
|
super(CmdId.TakeMailAttachmentScRsp);
|
||||||
|
|
||||||
var data = TakeMailAttachmentScRsp.newInstance();
|
var data = TakeMailAttachmentScRsp.newInstance();
|
||||||
|
|
||||||
for (int id : idList) {
|
for (Mail mail : mailList) {
|
||||||
data.addSuccMailIdList(id);
|
data.addSuccMailIdList(mail.getUniqueId());
|
||||||
}
|
|
||||||
|
|
||||||
for (GameItem item : items) {
|
if (mail.getAttachments() != null) {
|
||||||
data.getMutableAttachment().addItemList(item.toProto());
|
for (GameItem item : mail.getAttachments()) {
|
||||||
|
data.getMutableAttachment().addItemList(item.toProto());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setData(data);
|
this.setData(data);
|
||||||
|
|||||||
Reference in New Issue
Block a user