Add sign throttle config option.

Allows you to limit how often an Essentials sign can be spammed per player.
This commit is contained in:
KHobbits 2012-06-17 19:28:59 +01:00
parent 9f852b3a41
commit 9679a90d88
5 changed files with 49 additions and 2 deletions

View file

@ -179,4 +179,6 @@ public interface ISettings extends IConf
boolean isTeleportInvulnerability();
long getLoginAttackDelay();
int getSignUsePerSecond();
}

View file

@ -388,7 +388,8 @@ public class Settings implements ISettings
cancelAfkOnMove = _cancelAfkOnMove();
getFreezeAfkPlayers = _getFreezeAfkPlayers();
itemSpawnBl = _getItemSpawnBlacklist();
loginAttackDelay = _loginAttackDelay();
loginAttackDelay = _getLoginAttackDelay();
signUsePerSecond = _getSignUsePerSecond();
kits = _getKits();
chatFormats.clear();
}
@ -808,7 +809,7 @@ public class Settings implements ISettings
private long loginAttackDelay;
private long _loginAttackDelay()
private long _getLoginAttackDelay()
{
return config.getLong("login-attack-delay", 0) * 1000;
}
@ -819,4 +820,18 @@ public class Settings implements ISettings
return loginAttackDelay;
}
private int signUsePerSecond;
private int _getSignUsePerSecond()
{
final int perSec = config.getInt("sign-use-per-second", 4);
return perSec > 0 ? perSec : 1;
}
@Override
public int getSignUsePerSecond()
{
return signUsePerSecond;
}
}

View file

@ -21,6 +21,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
private transient final Teleport teleport;
private transient long teleportRequestTime;
private transient long lastOnlineActivity;
private transient long lastThrottledAction;
private transient long lastActivity = System.currentTimeMillis();
private boolean hidden = false;
private transient Location afkPosition = null;
@ -669,4 +670,23 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{
final boolean set = !vanished;
}
public boolean checkSignThrottle() {
if (isSignThrottled()) {
return true;
}
updateThrottle();
return false;
}
public boolean isSignThrottled()
{
final long minTime = lastThrottledAction + (1000 / ess.getSettings().getSignUsePerSecond());
return (System.currentTimeMillis() < minTime);
}
public void updateThrottle()
{
lastThrottledAction = System.currentTimeMillis();;
}
}

View file

@ -76,6 +76,10 @@ public class EssentialsSign
{
final ISign sign = new BlockSign(block);
final User user = ess.getUser(player);
if (user.checkSignThrottle())
{
return false;
}
try
{
return (user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".use")

View file

@ -223,6 +223,12 @@ enabledSigns:
#- weather
#- protection
# How many times per second can Essentials signs be interacted with.
# Values should be between 1-20, 20 being virtually no lag protection.s
# Lower numbers will reduce the possiblity of lag, but may annoy players.
sign-use-per-second: 4
# Backup runs a command while saving is disabled
backup:
# Interval in minutes