diff options
author | KHobbits <rob@khobbits.co.uk> | 2012-06-17 19:28:59 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2012-06-17 19:28:59 +0100 |
commit | 9679a90d88b240c1f29670389406e12301b64a9a (patch) | |
tree | cfccccd4bf64ee09bbc4f20e57d488f10815c506 | |
parent | 9f852b3a41151ad797c494deecd5caec54b182aa (diff) | |
download | Essentials-9679a90d88b240c1f29670389406e12301b64a9a.tar Essentials-9679a90d88b240c1f29670389406e12301b64a9a.tar.gz Essentials-9679a90d88b240c1f29670389406e12301b64a9a.tar.lz Essentials-9679a90d88b240c1f29670389406e12301b64a9a.tar.xz Essentials-9679a90d88b240c1f29670389406e12301b64a9a.zip |
Add sign throttle config option.
Allows you to limit how often an Essentials sign can be spammed per player.
-rw-r--r-- | Essentials/src/com/earth2me/essentials/ISettings.java | 2 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/Settings.java | 19 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/User.java | 20 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java | 4 | ||||
-rw-r--r-- | Essentials/src/config.yml | 6 |
5 files changed, 49 insertions, 2 deletions
diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index 3c6763cbe..71fc7f5dd 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -179,4 +179,6 @@ public interface ISettings extends IConf boolean isTeleportInvulnerability(); long getLoginAttackDelay(); + + int getSignUsePerSecond(); } diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index b1352b6c3..ec317dbfd 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -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; + } + } diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index 1ce991b66..e2cdc2b80 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -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();; + } } diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java index 21e70516e..389effc64 100644 --- a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java @@ -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") diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 0458d0f3f..391578791 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -222,6 +222,12 @@ enabledSigns: #- time #- 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: |