Switch fastplace to monitor 2 seconds + shortterm (10 ticks by default).

This commit is contained in:
asofold 2012-11-23 15:18:04 +01:00
parent df29e64bd9
commit bd65c1218f
5 changed files with 49 additions and 35 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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.";

View File

@ -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);