Add notify-player-of-mail-cooldown config option.

This feature allows for the ability to specify a cooldown for how often individual players are notified of their outstanding unread mails.
This commit is contained in:
Ali Moghnieh 2017-06-22 22:54:51 +01:00
parent 3831464665
commit 11a03bbce9
No known key found for this signature in database
GPG Key ID: F09D3A1BAF2E6D70
6 changed files with 26 additions and 5 deletions

View File

@ -462,10 +462,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
// New mail notification
if (user != null && !getSettings().isCommandDisabled("mail") && !command.getName().equals("mail") && user.isAuthorized("essentials.mail")) {
final List<String> mail = user.getMails();
if (mail != null && !mail.isEmpty()) {
user.sendMessage(tl("youHaveNewMail", mail.size()));
}
user.notifyOfMail();
}
//Print version even if admin command is not available #easteregg

View File

@ -275,7 +275,7 @@ public class EssentialsPlayerListener implements Listener {
user.sendMessage(tl("noNewMail")); // Only notify if they want us to.
}
} else {
user.sendMessage(tl("youHaveNewMail", mail.size()));
user.notifyOfMail();
}
}

View File

@ -277,4 +277,6 @@ public interface ISettings extends IConf {
boolean isAddingPrefixInPlayerlist();
boolean isAddingSuffixInPlayerlist();
int getNotifyPlayerOfMailCooldown();
}

View File

@ -1409,4 +1409,9 @@ public class Settings implements net.ess3.api.ISettings {
public boolean isAddingSuffixInPlayerlist() {
return config.getBoolean("add-suffix-in-playerlist", false);
}
@Override
public int getNotifyPlayerOfMailCooldown() {
return config.getInt("notify-player-of-mail-cooldown", 0);
}
}

View File

@ -28,6 +28,7 @@ import org.bukkit.potion.PotionEffectType;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.WeakHashMap;
@ -60,6 +61,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
private String afkMessage;
private long afkSince;
private Map<User, BigDecimal> confirmingPayments = new WeakHashMap<>();
private long lastNotifiedAboutMailsMs;
public User(final Player base, final IEssentials ess) {
super(base, ess);
@ -855,4 +857,15 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
return inventory.getItemInMainHand() != null ? inventory.getItemInMainHand() : inventory.getItemInOffHand();
}
}
public void notifyOfMail() {
List<String> mails = getMails();
if (mails != null && !mails.isEmpty()) {
int notifyPlayerOfMailCooldown = ess.getSettings().getNotifyPlayerOfMailCooldown() * 1000;
if (System.currentTimeMillis() - lastNotifiedAboutMailsMs >= notifyPlayerOfMailCooldown) {
sendMessage(tl("youHaveNewMail", mails.size()));
lastNotifiedAboutMailsMs = System.currentTimeMillis();
}
}
}
}

View File

@ -119,6 +119,10 @@ drop-items-if-full: false
# Should we notify players if they have no new mail?
notify-no-new-mail: true
# Specifies the duration (in seconds) between each time a player is notified of mail they have.
# Useful for servers with a lot of mail traffic.
notify-player-of-mail-cooldown: 60
# The motd and rules are now configured in the files motd.txt and rules.txt.
# When a command conflicts with another plugin, by default, Essentials will try to force the OTHER plugin to take priority.