Added timeout check to nonuke, so lag doesn't ban people.

This commit is contained in:
StevenLawson 2013-08-13 13:22:29 -04:00
parent 5c8f98089e
commit b94efb525f
2 changed files with 39 additions and 14 deletions

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Listener; package me.StevenLawson.TotalFreedomMod.Listener;
import me.StevenLawson.TotalFreedomMod.TFM_Heartbeat;
import me.StevenLawson.TotalFreedomMod.TFM_Log; import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea; import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
@ -74,16 +75,24 @@ public class TFM_BlockListener implements Listener
} }
} }
playerdata.incrementBlockDestroyCount(); Long lastRan = TFM_Heartbeat.getLastRan();
if (playerdata.getBlockDestroyCount() > TotalFreedomMod.nukeMonitorCountBreak) if (lastRan == null || lastRan + TotalFreedomMod.HEARTBEAT_RATE * 1000L < System.currentTimeMillis())
{ {
TFM_Util.bcastMsg(p.getName() + " is breaking blocks too fast!", ChatColor.RED); TFM_Log.warning("Heartbeat service timeout - can't check block place/break rates.");
TFM_Util.autoEject(p, "You are breaking blocks too fast. Nukers are not permitted on this server."); }
else
{
playerdata.incrementBlockDestroyCount();
if (playerdata.getBlockDestroyCount() > TotalFreedomMod.nukeMonitorCountBreak)
{
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.");
playerdata.resetBlockDestroyCount(); playerdata.resetBlockDestroyCount();
event.setCancelled(true); event.setCancelled(true);
return; return;
}
} }
} }
@ -142,16 +151,24 @@ public class TFM_BlockListener implements Listener
} }
} }
playerdata.incrementBlockPlaceCount(); Long lastRan = TFM_Heartbeat.getLastRan();
if (playerdata.getBlockPlaceCount() > TotalFreedomMod.nukeMonitorCountPlace) if (lastRan == null || lastRan + TotalFreedomMod.HEARTBEAT_RATE * 1000L < System.currentTimeMillis())
{ {
TFM_Util.bcastMsg(p.getName() + " is placing blocks too fast!", ChatColor.RED); TFM_Log.warning("Heartbeat service timeout - can't check block place/break rates.");
TFM_Util.autoEject(p, "You are placing blocks too fast."); }
else
{
playerdata.incrementBlockPlaceCount();
if (playerdata.getBlockPlaceCount() > TotalFreedomMod.nukeMonitorCountPlace)
{
TFM_Util.bcastMsg(p.getName() + " is placing blocks too fast!", ChatColor.RED);
TFM_Util.autoEject(p, "You are placing blocks too fast.");
playerdata.resetBlockPlaceCount(); playerdata.resetBlockPlaceCount();
event.setCancelled(true); event.setCancelled(true);
return; return;
}
} }
} }

View File

@ -9,6 +9,7 @@ public class TFM_Heartbeat extends BukkitRunnable
{ {
private final TotalFreedomMod plugin; private final TotalFreedomMod plugin;
private final Server server; private final Server server;
private static Long lastRan = null;
public TFM_Heartbeat(TotalFreedomMod instance) public TFM_Heartbeat(TotalFreedomMod instance)
{ {
@ -16,9 +17,16 @@ public class TFM_Heartbeat extends BukkitRunnable
this.server = plugin.getServer(); this.server = plugin.getServer();
} }
public static Long getLastRan()
{
return lastRan;
}
@Override @Override
public void run() public void run()
{ {
lastRan = System.currentTimeMillis();
for (Player p : server.getOnlinePlayers()) for (Player p : server.getOnlinePlayers())
{ {
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p); TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);