Search in sources :

Example 1 with MailData

use of io.github.nucleuspowered.nucleus.modules.mail.data.MailData in project Nucleus by NucleusPowered.

the class MailReadBase method createMessage.

private Text createMessage(final MailData md, final User user) {
    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MMM dd, yyyy").withZone(ZoneId.systemDefault());
    String name = Nucleus.getNucleus().getNameUtil().getNameFromUUID(md.getUuid());
    return Text.builder().append(Text.builder(name).color(TextColors.GREEN).style(TextStyles.UNDERLINE).onHover(TextActions.showText(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.mail.hover"))).onClick(TextActions.executeCallback(src -> {
        src.sendMessage(Text.builder().append(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.mail.date")).append(Text.of(" ", TextColors.WHITE, dtf.format(md.getDate()))).build());
        Text.Builder tb = Text.builder().append(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.mail.sender")).append(Text.of(" ", TextColors.WHITE, Nucleus.getNucleus().getNameUtil().getNameFromUUID(md.getUuid()))).append(Text.of(TextColors.YELLOW, " - "));
        // If the sender is not the server, allow right of reply.
        if (!md.getUuid().equals(Util.consoleFakeUUID)) {
            tb.append(Text.builder(Nucleus.getNucleus().getMessageProvider().getMessageWithFormat("standard.reply")).color(TextColors.GREEN).onHover(TextActions.showText(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.mail.reply.label", name))).onClick(TextActions.suggestCommand("/mail send " + name + " ")).build()).append(Text.of(TextColors.YELLOW, " - "));
        }
        src.sendMessage(tb.append(Text.builder(Nucleus.getNucleus().getMessageProvider().getMessageWithFormat("standard.delete")).color(TextColors.RED).onHover(TextActions.showText(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.mail.delete.label"))).onClick(TextActions.executeCallback(s -> {
            if (handler.removeMail(user, md)) {
                src.sendMessage(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.mail.delete.success"));
            } else {
                src.sendMessage(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.mail.delete.fail"));
            }
        })).build()).build());
        src.sendMessage(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.mail.message"));
        src.sendMessage(Text.of(TextColors.WHITE, md.getMessage()));
    })).build()).append(Text.of(": " + md.getMessage())).build();
}
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) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 2 with MailData

use of io.github.nucleuspowered.nucleus.modules.mail.data.MailData 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 3 with MailData

use of io.github.nucleuspowered.nucleus.modules.mail.data.MailData 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)

Example 4 with MailData

use of io.github.nucleuspowered.nucleus.modules.mail.data.MailData 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)4 Text (org.spongepowered.api.text.Text)4 Nucleus (io.github.nucleuspowered.nucleus.Nucleus)3 Util (io.github.nucleuspowered.nucleus.Util)3 MailMessage (io.github.nucleuspowered.nucleus.api.nucleusdata.MailMessage)3 NucleusMailService (io.github.nucleuspowered.nucleus.api.service.NucleusMailService)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Sponge (org.spongepowered.api.Sponge)3 User (org.spongepowered.api.entity.living.player.User)3 InternalServiceManagerTrait (io.github.nucleuspowered.nucleus.internal.traits.InternalServiceManagerTrait)2 MailUserDataModule (io.github.nucleuspowered.nucleus.modules.mail.datamodules.MailUserDataModule)2 InternalNucleusMailEvent (io.github.nucleuspowered.nucleus.modules.mail.events.InternalNucleusMailEvent)2 MailHandler (io.github.nucleuspowered.nucleus.modules.mail.handlers.MailHandler)2 ZoneId (java.time.ZoneId)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 Collection (java.util.Collection)2 Comparator (java.util.Comparator)2 CommandResult (org.spongepowered.api.command.CommandResult)2 CommandSource (org.spongepowered.api.command.CommandSource)2