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();
}
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);
}
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();
}
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()));
}
Aggregations