From bd65c1218f329f69b940b5dc2acb2bdf1ea18f63 Mon Sep 17 00:00:00 2001 From: asofold Date: Fri, 23 Nov 2012 15:18:04 +0100 Subject: [PATCH] Switch fastplace to monitor 2 seconds + shortterm (10 ticks by default). --- .../checks/blockplace/BlockPlaceConfig.java | 8 ++- .../checks/blockplace/BlockPlaceData.java | 6 +- .../checks/blockplace/FastPlace.java | 59 ++++++++++--------- .../nocheatplus/config/ConfPaths.java | 5 +- .../nocheatplus/config/DefaultConfig.java | 6 +- 5 files changed, 49 insertions(+), 35 deletions(-) diff --git a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceConfig.java b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceConfig.java index a72f4ef4..c8d8f739 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceConfig.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceConfig.java @@ -75,7 +75,9 @@ public class BlockPlaceConfig extends ACheckConfig { public final ActionList directionActions; public final boolean fastPlaceCheck; - public final long fastPlaceInterval; + public final int fastPlaceLimit; + public final int fastPlaceShortTermTicks; + public final int fastPlaceShortTermLimit; public final ActionList fastPlaceActions; public final boolean noSwingCheck; @@ -100,7 +102,9 @@ public class BlockPlaceConfig extends ACheckConfig { directionActions = data.getOptimizedActionList(ConfPaths.BLOCKPLACE_DIRECTION_ACTIONS, Permissions.BLOCKPLACE_DIRECTION); fastPlaceCheck = data.getBoolean(ConfPaths.BLOCKPLACE_FASTPLACE_CHECK); - fastPlaceInterval = data.getLong(ConfPaths.BLOCKPLACE_FASTPLACE_INTERVAL); + fastPlaceLimit = data.getInt(ConfPaths.BLOCKPLACE_FASTPLACE_LIMIT); + fastPlaceShortTermTicks = data.getInt(ConfPaths.BLOCKPLACE_FASTPLACE_SHORTTERM_TICKS); + fastPlaceShortTermLimit = data.getInt(ConfPaths.BLOCKPLACE_FASTPLACE_SHORTTERM_LIMIT); fastPlaceActions = data.getOptimizedActionList(ConfPaths.BLOCKPLACE_FASTPLACE_ACTIONS, Permissions.BLOCKPLACE_FASTPLACE); noSwingCheck = data.getBoolean(ConfPaths.BLOCKPLACE_NOSWING_CHECK); diff --git a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceData.java b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceData.java index a69397ea..ab405846 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceData.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceData.java @@ -8,6 +8,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.checks.access.ACheckData; import fr.neatmonster.nocheatplus.checks.access.CheckDataFactory; import fr.neatmonster.nocheatplus.checks.access.ICheckData; +import fr.neatmonster.nocheatplus.utilities.ActionFrequency; /* * M#"""""""'M dP dP MM"""""""`YM dP @@ -81,8 +82,9 @@ public class BlockPlaceData extends ACheckData { public double speedVL; // Data of the fast place check. - public long fastPlaceLastTime; - public boolean fastPlaceLastRefused; + public final ActionFrequency fastPlaceBuckets = new ActionFrequency(2, 1000); + public int fastPlaceShortTermTick = 0; + public int fastPlaceShortTermCount = 0; // Data of the no swing check. public boolean noSwingArmSwung = true; diff --git a/src/fr/neatmonster/nocheatplus/checks/blockplace/FastPlace.java b/src/fr/neatmonster/nocheatplus/checks/blockplace/FastPlace.java index 8458b72c..15e1ba68 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockplace/FastPlace.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockplace/FastPlace.java @@ -5,7 +5,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; -import fr.neatmonster.nocheatplus.utilities.LagMeasureTask; +import fr.neatmonster.nocheatplus.utilities.TickTask; /* * MM""""""""`M dP MM"""""""`YM dP @@ -41,33 +41,36 @@ public class FastPlace extends Check { final BlockPlaceConfig cc = BlockPlaceConfig.getConfig(player); final BlockPlaceData data = BlockPlaceData.getData(player); - boolean cancel = false; - - // Has the player placed blocks too quickly? - if (data.fastPlaceLastTime != 0 && System.currentTimeMillis() - data.fastPlaceLastTime < cc.fastPlaceInterval) { - if (!LagMeasureTask.skipCheck()) { - if (data.fastPlaceLastRefused) { - final double difference = cc.fastPlaceInterval - System.currentTimeMillis() - + data.fastPlaceLastTime; - - // He failed, increase his violation level. - data.fastPlaceVL += difference; - - // Execute whatever actions are associated with this check and the violation level and find out if - // we should cancel the event. - cancel = executeActions(player, data.fastPlaceVL, difference, cc.fastPlaceActions); - } - - data.fastPlaceLastRefused = true; - } - } else { - // Reward him by lowering his violation level. - data.fastPlaceVL *= 0.9D; - data.fastPlaceLastRefused = false; + data.fastPlaceBuckets.add(System.currentTimeMillis(), 1f); + + // Full period frequency. + final float fullScore = data.fastPlaceBuckets.score(1f); + + // Short term arrivals. + final int tick = TickTask.getTick(); + if (tick - data.fastPlaceShortTermTick < cc.fastPlaceShortTermTicks){ + // Within range, add. + data.fastPlaceShortTermCount ++; } - - data.fastPlaceLastTime = System.currentTimeMillis(); - - return cancel; + else{ + data.fastPlaceShortTermTick = tick; + data.fastPlaceShortTermCount = 1; + } + + // Find if one of both or both are violations: + final float fullViolation = fullScore - cc.fastPlaceLimit; + final float shortTermViolation = data.fastPlaceShortTermCount - cc.fastPlaceShortTermLimit; + final float violation = Math.max(fullViolation, shortTermViolation); + + boolean cancel = false; + if (violation > 0){ + final double change = violation / 1000; + data.fastPlaceVL += change; + cancel = executeActions(player, data.fastPlaceVL, change, cc.fastPlaceActions); + } + else if (data.fastPlaceVL > 0d && fullScore < cc.fastPlaceLimit * .75) + data.fastPlaceVL *= 0.95; + + return cancel; } } diff --git a/src/fr/neatmonster/nocheatplus/config/ConfPaths.java b/src/fr/neatmonster/nocheatplus/config/ConfPaths.java index 81cec5e1..8b2c07c0 100644 --- a/src/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/src/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -153,7 +153,10 @@ public abstract class ConfPaths { private static final String BLOCKPLACE_FASTPLACE = BLOCKPLACE + "fastplace."; public static final String BLOCKPLACE_FASTPLACE_CHECK = BLOCKPLACE_FASTPLACE + "active"; - public static final String BLOCKPLACE_FASTPLACE_INTERVAL = BLOCKPLACE_FASTPLACE + "interval"; + public static final String BLOCKPLACE_FASTPLACE_LIMIT = BLOCKPLACE_FASTPLACE + "limit"; + private static final String BLOCKPLACE_FASTPLACE_SHORTTERM = BLOCKPLACE_FASTPLACE + "shortterm."; + public static final String BLOCKPLACE_FASTPLACE_SHORTTERM_TICKS = BLOCKPLACE_FASTPLACE_SHORTTERM + "ticks"; + public static final String BLOCKPLACE_FASTPLACE_SHORTTERM_LIMIT = BLOCKPLACE_FASTPLACE_SHORTTERM + "limit"; public static final String BLOCKPLACE_FASTPLACE_ACTIONS = BLOCKPLACE_FASTPLACE + "actions"; private static final String BLOCKPLACE_NOSWING = BLOCKPLACE + "noswing."; diff --git a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java index c1ad9729..ac4d02b3 100644 --- a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -22,7 +22,7 @@ import org.bukkit.Material; public class DefaultConfig extends ConfigFile { /** NCP build needed for this config. */ - public static final int buildNumber = 236; + public static final int buildNumber = 256; /** * Instantiates a new default configuration. @@ -128,7 +128,9 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.BLOCKPLACE_DIRECTION_ACTIONS, "cancel vl>10 log:bdirection:0:3:if cancel"); set(ConfPaths.BLOCKPLACE_FASTPLACE_CHECK, true); - set(ConfPaths.BLOCKPLACE_FASTPLACE_INTERVAL, 95L); + set(ConfPaths.BLOCKPLACE_FASTPLACE_LIMIT, 22); + set(ConfPaths.BLOCKPLACE_FASTPLACE_SHORTTERM_TICKS, 10); + set(ConfPaths.BLOCKPLACE_FASTPLACE_SHORTTERM_LIMIT, 6); set(ConfPaths.BLOCKPLACE_FASTPLACE_ACTIONS, "cancel vl>100 log:fastplace:3:5:cif cancel"); set(ConfPaths.BLOCKPLACE_REACH_CHECK, true);