use of io.github.nucleuspowered.nucleus.modules.mail.datamodules.MailUserDataModule in project Nucleus by NucleusPowered.
the class MailHandler method getMailInternal.
public final List<MailData> getMailInternal(User player, MailFilter... filters) {
MailUserDataModule iqsu = plugin.getUserDataManager().getUnchecked(player).get(MailUserDataModule.class);
List<MailData> lmd = iqsu.getMail();
if (filters.length == 0 || lmd.isEmpty()) {
return Lists.newArrayList(lmd);
}
Optional<Predicate<MailMessage>> lmf = Arrays.stream(filters).map(x -> (Predicate<MailMessage>) x).reduce(Predicate::and);
return lmf.map(pred -> lmd.stream().filter(pred::test).collect(Collectors.toList())).orElse(lmd);
}
use of io.github.nucleuspowered.nucleus.modules.mail.datamodules.MailUserDataModule 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