Added message repeat prevention

This commit is contained in:
Jerom van der Sar 2012-11-27 20:02:39 +01:00
parent 878199c2d5
commit 92a6bbce94
2 changed files with 24 additions and 3 deletions

View File

@ -208,7 +208,7 @@ public class TFM_PlayerListener implements Listener
{ {
Location target_pos = p.getLocation().add(0, 1, 0); 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())) if (!target_pos.getWorld().equals(playerdata.getCagePos().getWorld()))
{ {
out_of_cage = true; out_of_cage = true;
@ -287,10 +287,22 @@ public class TFM_PlayerListener implements Listener
try try
{ {
final Player p = event.getPlayer(); final Player p = event.getPlayer();
String message = event.getMessage().trim();
TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p); TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p);
playerdata.incrementMsgCount(); 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 // check for spam
if (playerdata.getMsgCount() > 10) if (playerdata.getMsgCount() > 10)
{ {
@ -318,8 +330,6 @@ public class TFM_PlayerListener implements Listener
} }
} }
String message = event.getMessage().trim();
// strip color from messages // strip color from messages
message = ChatColor.stripColor(message); message = ChatColor.stripColor(message);

View File

@ -45,6 +45,7 @@ public class TFM_UserInfo
private boolean mp44_armed = false; private boolean mp44_armed = false;
private boolean mp44_firing = false; private boolean mp44_firing = false;
private int lockup_schedule_id = -1; private int lockup_schedule_id = -1;
private String last_message = "";
public TFM_UserInfo(Player player) public TFM_UserInfo(Player player)
{ {
@ -406,4 +407,14 @@ public class TFM_UserInfo
{ {
this.lockup_schedule_id = lockup_schedule_id; 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;
}
} }