use of io.github.nucleuspowered.nucleus.api.nucleusdata.MailMessage 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.api.nucleusdata.MailMessage in project Nucleus by NucleusPowered.
the class MailReadBase method executeCommand.
public CommandResult executeCommand(CommandSource src, final User target, Collection<NucleusMailService.MailFilter> lmf) {
List<MailData> lmd;
if (!lmf.isEmpty()) {
lmd = handler.getMailInternal(target, lmf.toArray(new NucleusMailService.MailFilter[lmf.size()]));
} else {
lmd = handler.getMailInternal(target);
}
if (lmd.isEmpty()) {
if (src instanceof Player && target.getUniqueId().equals(((Player) src).getUniqueId())) {
src.sendMessage(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat(!lmf.isEmpty() ? "command.mail.none.filter" : "command.mail.none.normal.self"));
} else {
src.sendMessage(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat(!lmf.isEmpty() ? "command.mail.none.filter" : "command.mail.none.normal.other", target.getName()));
}
return CommandResult.success();
}
List<Text> mails = lmd.stream().sorted(Comparator.comparing(MailMessage::getDate)).map(x -> createMessage(x, target)).collect(Collectors.toList());
// Paginate the mail.
PaginationService ps = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
PaginationList.Builder b = ps.builder().padding(Text.of(TextColors.GREEN, "-")).title(getHeader(src, target, !lmf.isEmpty())).contents(mails);
if (!(src instanceof Player)) {
b.linesPerPage(-1);
} else {
b.header(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("mail.header"));
}
b.sendTo(src);
return CommandResult.success();
}
Aggregations