Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* New `/mail sendtemp <time diff> <message>` command to send mail that will self-destruct after time diff. * New `/mail clear <number>` command to clear a specific mail item. * `/mail read` now tracks which mails you read and won't nag you about them. * A bunch of other flexibility since we store actual data instead of strings
- Loading branch information
Showing
24 changed files
with
622 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
Essentials/src/main/java/com/earth2me/essentials/MailServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.earth2me.essentials; | ||
|
||
import net.ess3.api.IUser; | ||
import net.essentialsx.api.v2.services.mail.MailService; | ||
import net.essentialsx.api.v2.services.mail.MailMessage; | ||
import net.essentialsx.api.v2.services.mail.MailSender; | ||
import org.bukkit.plugin.ServicePriority; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
|
||
import static com.earth2me.essentials.I18n.tl; | ||
|
||
public class MailServiceImpl implements MailService { | ||
private final transient ThreadLocal<SimpleDateFormat> df = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy/MM/dd HH:mm")); | ||
|
||
public MailServiceImpl(IEssentials ess) { | ||
ess.getServer().getServicesManager().register(MailService.class, this, ess, ServicePriority.Normal); | ||
} | ||
|
||
@Override | ||
public void sendMail(IUser recipient, MailSender sender, String message) { | ||
sendMail(recipient, sender, message, 0L); | ||
} | ||
|
||
@Override | ||
public void sendMail(IUser recipient, MailSender sender, String message, long expireAt) { | ||
sendMail(recipient, new MailMessage(false, false, sender.getName(), sender.getUUID(), System.currentTimeMillis(), expireAt, message)); | ||
} | ||
|
||
@Override | ||
public void sendLegacyMail(IUser recipient, String message) { | ||
sendMail(recipient, new MailMessage(false, true, null, null, 0L, 0L, message)); | ||
} | ||
|
||
private void sendMail(IUser recipient, MailMessage message) { | ||
final ArrayList<MailMessage> messages = recipient.getMailMessages(); | ||
messages.add(0, message); | ||
recipient.setMailList(messages); | ||
} | ||
|
||
@Override | ||
public String getMailLine(MailMessage mail) { | ||
final String message = mail.getMessage(); | ||
if (mail.isLegacy()) { | ||
return tl("mailMessage", message); | ||
} | ||
|
||
final String expire = mail.getTimeExpire() != 0 ? "Timed" : ""; | ||
return tl((mail.isRead() ? "mailFormatNewRead" : "mailFormatNew") + expire, df.get().format(new Date(mail.getTimeSent())), mail.getSenderUsername(), message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.