From 92a6bbce946dd45b7bae12363b778a7b29707a48 Mon Sep 17 00:00:00 2001 From: Jerom van der Sar Date: Tue, 27 Nov 2012 20:02:39 +0100 Subject: [PATCH] Added message repeat prevention --- .../Listener/TFM_PlayerListener.java | 16 +++++++++++++--- .../TotalFreedomMod/TFM_UserInfo.java | 11 +++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java index 4c7230f3..49b48210 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java @@ -208,7 +208,7 @@ public class TFM_PlayerListener implements Listener { Location target_pos = p.getLocation().add(0, 1, 0); - boolean out_of_cage = false; + boolean out_of_cage; if (!target_pos.getWorld().equals(playerdata.getCagePos().getWorld())) { out_of_cage = true; @@ -287,10 +287,22 @@ public class TFM_PlayerListener implements Listener try { final Player p = event.getPlayer(); + String message = event.getMessage().trim(); TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p); playerdata.incrementMsgCount(); + // check for message repeat + if(playerdata.getLastMessage().equalsIgnoreCase(message)) + { + TFM_Util.playerMsg(p, "Please do not repeat messages."); + event.setCancelled(true); + playerdata.setLastMessage(message); + return; + } + + playerdata.setLastMessage(message); + // check for spam if (playerdata.getMsgCount() > 10) { @@ -318,8 +330,6 @@ public class TFM_PlayerListener implements Listener } } - String message = event.getMessage().trim(); - // strip color from messages message = ChatColor.stripColor(message); diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_UserInfo.java b/src/me/StevenLawson/TotalFreedomMod/TFM_UserInfo.java index be8a351b..f2e1f3e6 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_UserInfo.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_UserInfo.java @@ -45,6 +45,7 @@ public class TFM_UserInfo private boolean mp44_armed = false; private boolean mp44_firing = false; private int lockup_schedule_id = -1; + private String last_message = ""; public TFM_UserInfo(Player player) { @@ -406,4 +407,14 @@ public class TFM_UserInfo { this.lockup_schedule_id = lockup_schedule_id; } + + public void setLastMessage(String last_message) + { + this.last_message = last_message; + } + + public String getLastMessage() + { + return this.last_message; + } }