Search in sources :

Example 1 with MailUserDataModule

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);
}
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 MailUserDataModule

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