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;
import me.StevenLawson.TotalFreedomMod.TFM_Heartbeat;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
@ -74,6 +75,13 @@ public class TFM_BlockListener implements Listener
}
}
Long lastRan = TFM_Heartbeat.getLastRan();
if (lastRan == null || lastRan + TotalFreedomMod.HEARTBEAT_RATE * 1000L < System.currentTimeMillis())
{
TFM_Log.warning("Heartbeat service timeout - can't check block place/break rates.");
}
else
{
playerdata.incrementBlockDestroyCount();
if (playerdata.getBlockDestroyCount() > TotalFreedomMod.nukeMonitorCountBreak)
{
@ -86,6 +94,7 @@ public class TFM_BlockListener implements Listener
return;
}
}
}
if (TotalFreedomMod.protectedAreasEnabled)
{
@ -142,6 +151,13 @@ public class TFM_BlockListener implements Listener
}
}
Long lastRan = TFM_Heartbeat.getLastRan();
if (lastRan == null || lastRan + TotalFreedomMod.HEARTBEAT_RATE * 1000L < System.currentTimeMillis())
{
TFM_Log.warning("Heartbeat service timeout - can't check block place/break rates.");
}
else
{
playerdata.incrementBlockPlaceCount();
if (playerdata.getBlockPlaceCount() > TotalFreedomMod.nukeMonitorCountPlace)
{
@ -154,6 +170,7 @@ public class TFM_BlockListener implements Listener
return;
}
}
}
if (TotalFreedomMod.protectedAreasEnabled)
{

View File

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