Add configuration option for silencing login and logout notifications (#89)
This commit is contained in:
parent
3043298640
commit
daf34703e4
|
|
@ -135,6 +135,7 @@ public class GriefPrevention extends JavaPlugin
|
||||||
|
|
||||||
public boolean config_spam_enabled; //whether or not to monitor for spam
|
public boolean config_spam_enabled; //whether or not to monitor for spam
|
||||||
public int config_spam_loginCooldownSeconds; //how long players must wait between logins. combats login spam.
|
public int config_spam_loginCooldownSeconds; //how long players must wait between logins. combats login spam.
|
||||||
|
public int config_spam_loginLogoutNotificationsPerMinute; //how many login/logout notifications to show per minute (global, not per player)
|
||||||
public ArrayList<String> config_spam_monitorSlashCommands; //the list of slash commands monitored for spam
|
public ArrayList<String> config_spam_monitorSlashCommands; //the list of slash commands monitored for spam
|
||||||
public boolean config_spam_banOffenders; //whether or not to ban spammers automatically
|
public boolean config_spam_banOffenders; //whether or not to ban spammers automatically
|
||||||
public String config_spam_banMessage; //message to show an automatically banned player
|
public String config_spam_banMessage; //message to show an automatically banned player
|
||||||
|
|
@ -564,6 +565,7 @@ public class GriefPrevention extends JavaPlugin
|
||||||
|
|
||||||
this.config_spam_enabled = config.getBoolean("GriefPrevention.Spam.Enabled", true);
|
this.config_spam_enabled = config.getBoolean("GriefPrevention.Spam.Enabled", true);
|
||||||
this.config_spam_loginCooldownSeconds = config.getInt("GriefPrevention.Spam.LoginCooldownSeconds", 60);
|
this.config_spam_loginCooldownSeconds = config.getInt("GriefPrevention.Spam.LoginCooldownSeconds", 60);
|
||||||
|
this.config_spam_loginLogoutNotificationsPerMinute = config.getInt("GriefPrevention.Spam.LoginLogoutNotificationsPerMinute", 5);
|
||||||
this.config_spam_warningMessage = config.getString("GriefPrevention.Spam.WarningMessage", "Please reduce your noise level. Spammers will be banned.");
|
this.config_spam_warningMessage = config.getString("GriefPrevention.Spam.WarningMessage", "Please reduce your noise level. Spammers will be banned.");
|
||||||
this.config_spam_allowedIpAddresses = config.getString("GriefPrevention.Spam.AllowedIpAddresses", "1.2.3.4; 5.6.7.8");
|
this.config_spam_allowedIpAddresses = config.getString("GriefPrevention.Spam.AllowedIpAddresses", "1.2.3.4; 5.6.7.8");
|
||||||
this.config_spam_banOffenders = config.getBoolean("GriefPrevention.Spam.BanOffenders", true);
|
this.config_spam_banOffenders = config.getBoolean("GriefPrevention.Spam.BanOffenders", true);
|
||||||
|
|
@ -817,6 +819,7 @@ public class GriefPrevention extends JavaPlugin
|
||||||
|
|
||||||
outConfig.set("GriefPrevention.Spam.Enabled", this.config_spam_enabled);
|
outConfig.set("GriefPrevention.Spam.Enabled", this.config_spam_enabled);
|
||||||
outConfig.set("GriefPrevention.Spam.LoginCooldownSeconds", this.config_spam_loginCooldownSeconds);
|
outConfig.set("GriefPrevention.Spam.LoginCooldownSeconds", this.config_spam_loginCooldownSeconds);
|
||||||
|
outConfig.set("GriefPrevention.Spam.LoginLogoutNotificationsPerMinute", this.config_spam_loginLogoutNotificationsPerMinute);
|
||||||
outConfig.set("GriefPrevention.Spam.ChatSlashCommands", slashCommandsToMonitor);
|
outConfig.set("GriefPrevention.Spam.ChatSlashCommands", slashCommandsToMonitor);
|
||||||
outConfig.set("GriefPrevention.Spam.WhisperSlashCommands", whisperCommandsToMonitor);
|
outConfig.set("GriefPrevention.Spam.WhisperSlashCommands", whisperCommandsToMonitor);
|
||||||
outConfig.set("GriefPrevention.Spam.WarningMessage", this.config_spam_warningMessage);
|
outConfig.set("GriefPrevention.Spam.WarningMessage", this.config_spam_warningMessage);
|
||||||
|
|
|
||||||
|
|
@ -924,8 +924,12 @@ class PlayerEventHandler implements Listener
|
||||||
//determines whether or not a login or logout notification should be silenced, depending on how many there have been in the last minute
|
//determines whether or not a login or logout notification should be silenced, depending on how many there have been in the last minute
|
||||||
private boolean shouldSilenceNotification()
|
private boolean shouldSilenceNotification()
|
||||||
{
|
{
|
||||||
|
if (instance.config_spam_loginLogoutNotificationsPerMinute <= 0)
|
||||||
|
{
|
||||||
|
return false; // not silencing login/logout notifications
|
||||||
|
}
|
||||||
|
|
||||||
final long ONE_MINUTE = 60000;
|
final long ONE_MINUTE = 60000;
|
||||||
final int MAX_ALLOWED = 5;
|
|
||||||
Long now = Calendar.getInstance().getTimeInMillis();
|
Long now = Calendar.getInstance().getTimeInMillis();
|
||||||
|
|
||||||
//eliminate any expired entries (longer than a minute ago)
|
//eliminate any expired entries (longer than a minute ago)
|
||||||
|
|
@ -945,7 +949,7 @@ class PlayerEventHandler implements Listener
|
||||||
//add the new entry
|
//add the new entry
|
||||||
this.recentLoginLogoutNotifications.add(now);
|
this.recentLoginLogoutNotifications.add(now);
|
||||||
|
|
||||||
return this.recentLoginLogoutNotifications.size() > MAX_ALLOWED;
|
return this.recentLoginLogoutNotifications.size() > instance.config_spam_loginLogoutNotificationsPerMinute;
|
||||||
}
|
}
|
||||||
|
|
||||||
//when a player drops an item
|
//when a player drops an item
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user