Search in sources :

Example 1 with MailMessage

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);
}
Also used : Arrays(java.util.Arrays) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) MailUserDataModule(io.github.nucleuspowered.nucleus.modules.mail.datamodules.MailUserDataModule) User(org.spongepowered.api.entity.living.player.User) NucleusPlugin(io.github.nucleuspowered.nucleus.NucleusPlugin) Predicate(java.util.function.Predicate) Sponge(org.spongepowered.api.Sponge) NucleusMailService(io.github.nucleuspowered.nucleus.api.service.NucleusMailService) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) InternalNucleusMailEvent(io.github.nucleuspowered.nucleus.modules.mail.events.InternalNucleusMailEvent) List(java.util.List) Lists(com.google.common.collect.Lists) MailMessage(io.github.nucleuspowered.nucleus.api.nucleusdata.MailMessage) Text(org.spongepowered.api.text.Text) MailData(io.github.nucleuspowered.nucleus.modules.mail.data.MailData) Optional(java.util.Optional) Util(io.github.nucleuspowered.nucleus.Util) MailData(io.github.nucleuspowered.nucleus.modules.mail.data.MailData) MailUserDataModule(io.github.nucleuspowered.nucleus.modules.mail.datamodules.MailUserDataModule) Predicate(java.util.function.Predicate)

Example 2 with MailMessage

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();
}
Also used : CommandResult(org.spongepowered.api.command.CommandResult) TextActions(org.spongepowered.api.text.action.TextActions) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) User(org.spongepowered.api.entity.living.player.User) CommandSource(org.spongepowered.api.command.CommandSource) TextStyles(org.spongepowered.api.text.format.TextStyles) Collection(java.util.Collection) Sponge(org.spongepowered.api.Sponge) NucleusMailService(io.github.nucleuspowered.nucleus.api.service.NucleusMailService) PaginationService(org.spongepowered.api.service.pagination.PaginationService) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) PaginationList(org.spongepowered.api.service.pagination.PaginationList) InternalServiceManagerTrait(io.github.nucleuspowered.nucleus.internal.traits.InternalServiceManagerTrait) List(java.util.List) MailMessage(io.github.nucleuspowered.nucleus.api.nucleusdata.MailMessage) Text(org.spongepowered.api.text.Text) MailData(io.github.nucleuspowered.nucleus.modules.mail.data.MailData) MailHandler(io.github.nucleuspowered.nucleus.modules.mail.handlers.MailHandler) DateTimeFormatter(java.time.format.DateTimeFormatter) Util(io.github.nucleuspowered.nucleus.Util) Player(org.spongepowered.api.entity.living.player.Player) Comparator(java.util.Comparator) TextColors(org.spongepowered.api.text.format.TextColors) NucleusMailService(io.github.nucleuspowered.nucleus.api.service.NucleusMailService) Player(org.spongepowered.api.entity.living.player.Player) PaginationList(org.spongepowered.api.service.pagination.PaginationList) MailData(io.github.nucleuspowered.nucleus.modules.mail.data.MailData) Text(org.spongepowered.api.text.Text) PaginationService(org.spongepowered.api.service.pagination.PaginationService)

Aggregations

Nucleus (io.github.nucleuspowered.nucleus.Nucleus)2 Util (io.github.nucleuspowered.nucleus.Util)2 MailMessage (io.github.nucleuspowered.nucleus.api.nucleusdata.MailMessage)2 NucleusMailService (io.github.nucleuspowered.nucleus.api.service.NucleusMailService)2 MailData (io.github.nucleuspowered.nucleus.modules.mail.data.MailData)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Sponge (org.spongepowered.api.Sponge)2 User (org.spongepowered.api.entity.living.player.User)2 Text (org.spongepowered.api.text.Text)2 Lists (com.google.common.collect.Lists)1 NucleusPlugin (io.github.nucleuspowered.nucleus.NucleusPlugin)1 InternalServiceManagerTrait (io.github.nucleuspowered.nucleus.internal.traits.InternalServiceManagerTrait)1 MailUserDataModule (io.github.nucleuspowered.nucleus.modules.mail.datamodules.MailUserDataModule)1 InternalNucleusMailEvent (io.github.nucleuspowered.nucleus.modules.mail.events.InternalNucleusMailEvent)1 MailHandler (io.github.nucleuspowered.nucleus.modules.mail.handlers.MailHandler)1 Instant (java.time.Instant)1 ZoneId (java.time.ZoneId)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 Arrays (java.util.Arrays)1