More tweaks to nonuke and spam prevention.

This commit is contained in:
StevenLawson 2013-08-13 13:42:43 -04:00
parent b94efb525f
commit b0090a5412
3 changed files with 30 additions and 52 deletions

View File

@ -62,8 +62,7 @@ public class TFM_BlockListener implements Listener
if (out_of_range) if (out_of_range)
{ {
playerdata.incrementFreecamDestroyCount(); if (playerdata.incrementAndGetFreecamDestroyCount() > TotalFreedomMod.freecamTriggerCount)
if (playerdata.getFreecamDestroyCount() > TotalFreedomMod.freecamTriggerCount)
{ {
TFM_Util.bcastMsg(p.getName() + " has been flagged for possible freecam nuking.", ChatColor.RED); TFM_Util.bcastMsg(p.getName() + " has been flagged for possible freecam nuking.", ChatColor.RED);
TFM_Util.autoEject(p, "Freecam (extended range) block breaking is not permitted on this server."); TFM_Util.autoEject(p, "Freecam (extended range) block breaking is not permitted on this server.");
@ -82,8 +81,7 @@ public class TFM_BlockListener implements Listener
} }
else else
{ {
playerdata.incrementBlockDestroyCount(); if (playerdata.incrementAndGetBlockDestroyCount() > TotalFreedomMod.nukeMonitorCountBreak)
if (playerdata.getBlockDestroyCount() > TotalFreedomMod.nukeMonitorCountBreak)
{ {
TFM_Util.bcastMsg(p.getName() + " is breaking blocks too fast!", ChatColor.RED); TFM_Util.bcastMsg(p.getName() + " is breaking blocks too fast!", ChatColor.RED);
TFM_Util.autoEject(p, "You are breaking blocks too fast. Nukers are not permitted on this server."); TFM_Util.autoEject(p, "You are breaking blocks too fast. Nukers are not permitted on this server.");
@ -138,8 +136,7 @@ public class TFM_BlockListener implements Listener
if (out_of_range) if (out_of_range)
{ {
playerdata.incrementFreecamPlaceCount(); if (playerdata.incrementAndGetFreecamPlaceCount() > TotalFreedomMod.freecamTriggerCount)
if (playerdata.getFreecamPlaceCount() > TotalFreedomMod.freecamTriggerCount)
{ {
TFM_Util.bcastMsg(p.getName() + " has been flagged for possible freecam building.", ChatColor.RED); TFM_Util.bcastMsg(p.getName() + " has been flagged for possible freecam building.", ChatColor.RED);
TFM_Util.autoEject(p, "Freecam (extended range) block building is not permitted on this server."); TFM_Util.autoEject(p, "Freecam (extended range) block building is not permitted on this server.");
@ -158,8 +155,7 @@ public class TFM_BlockListener implements Listener
} }
else else
{ {
playerdata.incrementBlockPlaceCount(); if (playerdata.incrementAndGetBlockPlaceCount() > TotalFreedomMod.nukeMonitorCountPlace)
if (playerdata.getBlockPlaceCount() > TotalFreedomMod.nukeMonitorCountPlace)
{ {
TFM_Util.bcastMsg(p.getName() + " is placing blocks too fast!", ChatColor.RED); TFM_Util.bcastMsg(p.getName() + " is placing blocks too fast!", ChatColor.RED);
TFM_Util.autoEject(p, "You are placing blocks too fast."); TFM_Util.autoEject(p, "You are placing blocks too fast.");

View File

@ -30,6 +30,7 @@ import org.bukkit.util.Vector;
public class TFM_PlayerListener implements Listener public class TFM_PlayerListener implements Listener
{ {
private static final List<String> BLOCKED_MUTED_CMDS = Arrays.asList(StringUtils.split("say,me,msg,m,tell,r,reply,mail,email", ",")); private static final List<String> BLOCKED_MUTED_CMDS = Arrays.asList(StringUtils.split("say,me,msg,m,tell,r,reply,mail,email", ","));
private static final int MSG_PER_HEARTBEAT = 10;
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) public void onPlayerInteract(PlayerInteractEvent event)
@ -395,18 +396,25 @@ public class TFM_PlayerListener implements Listener
String message = event.getMessage().trim(); String message = event.getMessage().trim();
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p); TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);
playerdata.incrementMsgCount();
// Check for spam // Check for spam
if (playerdata.getMsgCount() > 10) Long lastRan = TFM_Heartbeat.getLastRan();
if (lastRan == null || lastRan + TotalFreedomMod.HEARTBEAT_RATE * 1000L < System.currentTimeMillis())
{ {
TFM_Util.bcastMsg(p.getName() + " was automatically kicked for spamming chat.", ChatColor.RED); TFM_Log.warning("Heartbeat service timeout - can't check block place/break rates.");
TFM_Util.autoEject(p, "Kicked for spamming chat."); }
else
{
if (playerdata.incrementAndGetMsgCount() > MSG_PER_HEARTBEAT)
{
TFM_Util.bcastMsg(p.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
TFM_Util.autoEject(p, "Kicked for spamming chat.");
playerdata.resetMsgCount(); playerdata.resetMsgCount();
event.setCancelled(true); event.setCancelled(true);
return; return;
}
} }
// Check for message repeat // Check for message repeat
@ -491,10 +499,9 @@ public class TFM_PlayerListener implements Listener
Player p = event.getPlayer(); Player p = event.getPlayer();
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p); TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);
playerdata.incrementMsgCount();
playerdata.setLastCommand(command); playerdata.setLastCommand(command);
if (playerdata.getMsgCount() > 10) if (playerdata.incrementAndGetMsgCount() > MSG_PER_HEARTBEAT)
{ {
TFM_Util.bcastMsg(p.getName() + " was automatically kicked for spamming commands.", ChatColor.RED); TFM_Util.bcastMsg(p.getName() + " was automatically kicked for spamming commands.", ChatColor.RED);
TFM_Util.autoEject(p, "Kicked for spamming commands."); TFM_Util.autoEject(p, "Kicked for spamming commands.");

View File

@ -219,24 +219,14 @@ public class TFM_PlayerData
this.msg_count = 0; this.msg_count = 0;
} }
public void incrementMsgCount() public int incrementAndGetMsgCount()
{ {
this.msg_count++; return this.msg_count++;
} }
public int getMsgCount() public int incrementAndGetBlockDestroyCount()
{ {
return msg_count; return this.block_destroy_total++;
}
public void incrementBlockDestroyCount()
{
this.block_destroy_total++;
}
public int getBlockDestroyCount()
{
return block_destroy_total;
} }
public void resetBlockDestroyCount() public void resetBlockDestroyCount()
@ -244,14 +234,9 @@ public class TFM_PlayerData
this.block_destroy_total = 0; this.block_destroy_total = 0;
} }
public void incrementBlockPlaceCount() public int incrementAndGetBlockPlaceCount()
{ {
this.block_place_total++; return this.block_place_total++;
}
public int getBlockPlaceCount()
{
return block_place_total;
} }
public void resetBlockPlaceCount() public void resetBlockPlaceCount()
@ -259,14 +244,9 @@ public class TFM_PlayerData
this.block_place_total = 0; this.block_place_total = 0;
} }
public void incrementFreecamDestroyCount() public int incrementAndGetFreecamDestroyCount()
{ {
this.freecam_destroy_count++; return this.freecam_destroy_count++;
}
public int getFreecamDestroyCount()
{
return freecam_destroy_count;
} }
public void resetFreecamDestroyCount() public void resetFreecamDestroyCount()
@ -274,14 +254,9 @@ public class TFM_PlayerData
this.freecam_destroy_count = 0; this.freecam_destroy_count = 0;
} }
public void incrementFreecamPlaceCount() public int incrementAndGetFreecamPlaceCount()
{ {
this.freecam_place_count++; return this.freecam_place_count++;
}
public int getFreecamPlaceCount()
{
return freecam_place_count;
} }
public void resetFreecamPlaceCount() public void resetFreecamPlaceCount()