Update mail state on ping

This commit is contained in:
Melledy
2025-10-30 08:28:40 -07:00
parent 7c5c0e21b7
commit 3a44ebbdc3
4 changed files with 90 additions and 39 deletions

View File

@@ -27,6 +27,8 @@ public class Mailbox extends PlayerManager implements GameDatabaseObject, Iterab
private List<GameMail> list;
private transient boolean newState;
@Deprecated // Morphia only
public Mailbox() {
@@ -41,6 +43,10 @@ public class Mailbox extends PlayerManager implements GameDatabaseObject, Iterab
this.save();
}
public void clearNewState() {
this.newState = false;
}
// TODO optimize to an O(n) algorithm like a map
public GameMail getMailById(int id) {
return this.getList().stream()
@@ -56,6 +62,9 @@ public class Mailbox extends PlayerManager implements GameDatabaseObject, Iterab
// Add to mail list
this.list.add(mail);
// Set state
this.newState = true;
// Save to database
Nebula.getGameDatabase().update(this, getUid(), "lastMailId", this.getLastMailId());
Nebula.getGameDatabase().addToList(this, getUid(), "list", mail);