diff --git a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java index bbed8b5..c4d71fe 100644 --- a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -567,7 +567,7 @@ public class GriefPrevention extends JavaPlugin this.config_spam_banMessage = config.getString("GriefPrevention.Spam.BanMessage", "Banned for spam."); String slashCommandsToMonitor = config.getString("GriefPrevention.Spam.MonitorSlashCommands", "/me;/global;/local"); 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_punishLogout = config.getBoolean("GriefPrevention.PvP.PunishLogout", true); diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerData.java b/src/me/ryanhamshire/GriefPrevention/PlayerData.java index cfaea8c..a04911b 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerData.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerData.java @@ -78,9 +78,6 @@ public class PlayerData //whether this player was recently warned about building outside land claims 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) long lastSiegeEndTimeStamp = 0; diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java index 462e782..54bcac6 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Collection; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -931,20 +932,24 @@ class PlayerEventHandler implements Listener } //when a player dies... - @EventHandler(priority = EventPriority.HIGHEST) + private HashMap deathTimestamps = new HashMap(); + @EventHandler(priority = EventPriority.HIGHEST) void onPlayerDeath(PlayerDeathEvent event) { //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(); - if(now - playerData.lastDeathTimeStamp < GriefPrevention.instance.config_spam_deathMessageCooldownSeconds * 1000) + if(lastDeathTime != null && now - lastDeathTime < GriefPrevention.instance.config_spam_deathMessageCooldownSeconds * 1000) { - event.setDeathMessage(""); + player.sendMessage(event.getDeathMessage()); //let the player assume his death message was broadcasted to everyone + event.setDeathMessage(""); } - playerData.lastDeathTimeStamp = now; + this.deathTimestamps.put(player.getUniqueId(), now); //these are related to locking dropped items on death to prevent theft + PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId()); playerData.dropsAreUnlocked = false; playerData.receivedDropUnlockAdvertisement = false; }