use of io.github.nucleuspowered.nucleus.modules.mail.events.InternalNucleusMailEvent in project Nucleus by NucleusPowered.
the class MailHandler method sendMail.
@Override
public void sendMail(User playerFrom, User playerTo, String message) {
MailUserDataModule iqsu;
try {
iqsu = plugin.getUserDataManager().getUnchecked(playerTo).get(MailUserDataModule.class);
} catch (Exception e) {
e.printStackTrace();
return;
}
// that's that.
if (Sponge.getEventManager().post(new InternalNucleusMailEvent(playerFrom, playerTo, message))) {
playerFrom.getPlayer().ifPresent(x -> x.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("message.cancel")));
return;
}
MailData md = new MailData(playerFrom == null ? Util.consoleFakeUUID : playerFrom.getUniqueId(), Instant.now(), message);
iqsu.addMail(md);
Text from = playerFrom == null ? Text.of(Sponge.getServer().getConsole().getName()) : plugin.getNameUtil().getName(playerFrom);
playerTo.getPlayer().ifPresent(x -> x.sendMessage(Text.builder().append(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("mail.youvegotmail")).append(Text.of(" ", from)).build()));
}
Aggregations