Search in sources :

Example 1 with InternalNucleusMailEvent

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()));
}
Also used : InternalNucleusMailEvent(io.github.nucleuspowered.nucleus.modules.mail.events.InternalNucleusMailEvent) MailData(io.github.nucleuspowered.nucleus.modules.mail.data.MailData) Text(org.spongepowered.api.text.Text) MailUserDataModule(io.github.nucleuspowered.nucleus.modules.mail.datamodules.MailUserDataModule)

Aggregations

MailData (io.github.nucleuspowered.nucleus.modules.mail.data.MailData)1 MailUserDataModule (io.github.nucleuspowered.nucleus.modules.mail.datamodules.MailUserDataModule)1 InternalNucleusMailEvent (io.github.nucleuspowered.nucleus.modules.mail.events.InternalNucleusMailEvent)1 Text (org.spongepowered.api.text.Text)1