Improve death message spam blocker.

Can't mitigate by logging out and back in.  Made blockage less obvious
to spammer.  Increased default cooldown to two minutes.
This commit is contained in:
ryanhamshire 2016-06-30 14:00:18 -07:00
parent 65f122aa95
commit a97d5c191a
3 changed files with 11 additions and 9 deletions

View File

@ -567,7 +567,7 @@ public class GriefPrevention extends JavaPlugin
this.config_spam_banMessage = config.getString("GriefPrevention.Spam.BanMessage", "Banned for spam."); this.config_spam_banMessage = config.getString("GriefPrevention.Spam.BanMessage", "Banned for spam.");
String slashCommandsToMonitor = config.getString("GriefPrevention.Spam.MonitorSlashCommands", "/me;/global;/local"); String slashCommandsToMonitor = config.getString("GriefPrevention.Spam.MonitorSlashCommands", "/me;/global;/local");
slashCommandsToMonitor = config.getString("GriefPrevention.Spam.ChatSlashCommands", slashCommandsToMonitor); slashCommandsToMonitor = config.getString("GriefPrevention.Spam.ChatSlashCommands", slashCommandsToMonitor);
this.config_spam_deathMessageCooldownSeconds = config.getInt("GriefPrevention.Spam.DeathMessageCooldownSeconds", 60); this.config_spam_deathMessageCooldownSeconds = config.getInt("GriefPrevention.Spam.DeathMessageCooldownSeconds", 120);
this.config_pvp_protectFreshSpawns = config.getBoolean("GriefPrevention.PvP.ProtectFreshSpawns", true); this.config_pvp_protectFreshSpawns = config.getBoolean("GriefPrevention.PvP.ProtectFreshSpawns", true);
this.config_pvp_punishLogout = config.getBoolean("GriefPrevention.PvP.PunishLogout", true); this.config_pvp_punishLogout = config.getBoolean("GriefPrevention.PvP.PunishLogout", true);

View File

@ -78,9 +78,6 @@ public class PlayerData
//whether this player was recently warned about building outside land claims //whether this player was recently warned about building outside land claims
boolean warnedAboutBuildingOutsideClaims = false; boolean warnedAboutBuildingOutsideClaims = false;
//timestamp of last death, for use in preventing death message spam
long lastDeathTimeStamp = 0;
//timestamp when last siege ended (where this player was the defender) //timestamp when last siege ended (where this player was the defender)
long lastSiegeEndTimeStamp = 0; long lastSiegeEndTimeStamp = 0;

View File

@ -23,6 +23,7 @@ import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -931,20 +932,24 @@ class PlayerEventHandler implements Listener
} }
//when a player dies... //when a player dies...
private HashMap<UUID, Long> deathTimestamps = new HashMap<UUID, Long>();
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
void onPlayerDeath(PlayerDeathEvent event) void onPlayerDeath(PlayerDeathEvent event)
{ {
//FEATURE: prevent death message spam by implementing a "cooldown period" for death messages //FEATURE: prevent death message spam by implementing a "cooldown period" for death messages
PlayerData playerData = this.dataStore.getPlayerData(event.getEntity().getUniqueId()); Player player = event.getEntity();
Long lastDeathTime = this.deathTimestamps.get(player.getUniqueId());
long now = Calendar.getInstance().getTimeInMillis(); long now = Calendar.getInstance().getTimeInMillis();
if(now - playerData.lastDeathTimeStamp < GriefPrevention.instance.config_spam_deathMessageCooldownSeconds * 1000) if(lastDeathTime != null && now - lastDeathTime < GriefPrevention.instance.config_spam_deathMessageCooldownSeconds * 1000)
{ {
player.sendMessage(event.getDeathMessage()); //let the player assume his death message was broadcasted to everyone
event.setDeathMessage(""); event.setDeathMessage("");
} }
playerData.lastDeathTimeStamp = now; this.deathTimestamps.put(player.getUniqueId(), now);
//these are related to locking dropped items on death to prevent theft //these are related to locking dropped items on death to prevent theft
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
playerData.dropsAreUnlocked = false; playerData.dropsAreUnlocked = false;
playerData.receivedDropUnlockAdvertisement = false; playerData.receivedDropUnlockAdvertisement = false;
} }