Implement welcome mail

This commit is contained in:
Melledy
2025-11-10 04:12:46 -08:00
parent db5209ff06
commit 04b76135fe
3 changed files with 44 additions and 4 deletions

View File

@@ -1,7 +1,9 @@
package emu.nebula;
import java.util.List;
import java.util.Set;
import emu.nebula.game.inventory.ItemParam;
import lombok.Getter;
@Getter
@@ -99,6 +101,7 @@ public class Config {
public boolean skipIntro = false;
public boolean unlockInstances = true;
public int dailyResetHour = 0;
public WelcomeMail welcomeMail = new WelcomeMail();
}
@Getter
@@ -112,4 +115,24 @@ public class Config {
public boolean packets = false;
}
@Getter
public static class WelcomeMail {
public String title;
public String sender;
public String content;
public List<ItemParam> attachments;
public WelcomeMail() {
this.title = "Welcome to a Nebula server";
this.sender = "Server";
this.content = "Welcome to Nebula! Please take these items as a starter gift.";
this.attachments = List.of(
new ItemParam(86009, 1),
new ItemParam(86003, 1),
new ItemParam(1, 1_000_000),
new ItemParam(2, 30_000)
);
}
}
}

View File

@@ -8,7 +8,6 @@ import java.util.stream.Collectors;
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id;
import emu.nebula.Nebula;
import emu.nebula.database.GameDatabaseObject;
import emu.nebula.game.player.Player;
@@ -70,8 +69,10 @@ public class Mailbox extends PlayerManager implements GameDatabaseObject, Iterab
// Add to mail list
this.list.add(mail);
// Set state
// Set new state only if player has a session connected
if (this.getPlayer().hasSession()) {
this.newState = true;
}
// Save to database
Nebula.getGameDatabase().update(this, getUid(), "lastMailId", this.getLastMailId());
@@ -211,6 +212,19 @@ public class Mailbox extends PlayerManager implements GameDatabaseObject, Iterab
return removed;
}
public void sendWelcomeMail() {
var welcomeMail = Nebula.getConfig().getServerOptions().welcomeMail;
if (welcomeMail == null) return;
var mail = new GameMail(welcomeMail.getTitle(), welcomeMail.getSender(), welcomeMail.getContent());
for (var param : welcomeMail.getAttachments()) {
mail.addAttachment(param.getId(), param.getCount());
}
this.sendMail(mail);
}
@Override
public Iterator<GameMail> iterator() {
return this.getList().iterator();

View File

@@ -95,7 +95,10 @@ public class PlayerModule extends GameContextModule {
player.onLoad();
player.save();
// Put in cache
// Send welcome mail
player.getMailbox().sendWelcomeMail();
// Put in player cache
this.addToCache(player);
// Set player for session