AutoSign: Allow skipping empty signs.

This commit is contained in:
asofold 2015-03-11 22:19:21 +01:00
parent 0973149f0f
commit 9c75a07378
4 changed files with 292 additions and 280 deletions

View File

@ -18,6 +18,7 @@ import fr.neatmonster.nocheatplus.utilities.TickTask;
public class AutoSign extends Check {
// TODO: Make these configurable.
/** Reference time that is needed to edit the most complicated sign :). */
private static long maxEditTime = 1500;
/** Fastest time "possible" estimate for an empty sign. */
@ -40,6 +41,7 @@ public class AutoSign extends Check {
final long time = System.currentTimeMillis();
tags.clear();
final BlockPlaceData data = BlockPlaceData.getData(player);
final BlockPlaceConfig cc = BlockPlaceConfig.getConfig(player);
Material mat = block.getType();
if (mat == Material.SIGN_POST || mat == Material.WALL_SIGN) {
mat = Material.SIGN;
@ -56,7 +58,10 @@ public class AutoSign extends Check {
// check time, mind lag.
final long editTime = time - data.autoSignPlacedTime;
long expected = getExpectedEditTime(lines);
long expected = getExpectedEditTime(lines, cc.autoSignSkipEmpty);
if (expected == 0) {
return false;
}
expected = (long) (expected / TickTask.getLag(expected, true));
if (expected > editTime){
@ -66,7 +71,7 @@ public class AutoSign extends Check {
return false;
}
private long getExpectedEditTime(final String[] lines) {
private long getExpectedEditTime(final String[] lines, final boolean skipEmpty) {
long expected = minEditTime;
int n = 0;
for (String line : lines){
@ -82,6 +87,9 @@ public class AutoSign extends Check {
}
}
}
if (skipEmpty && n == 0) {
return 0;
}
if (n > 1){
expected += minLineTime * n;
}

View File

@ -65,6 +65,7 @@ public class BlockPlaceConfig extends ACheckConfig {
public final ActionList againstActions;
public final boolean autoSignCheck;
public final boolean autoSignSkipEmpty;
public final ActionList autoSignActions;
public final boolean directionCheck;
@ -100,6 +101,7 @@ public class BlockPlaceConfig extends ACheckConfig {
againstActions = data.getOptimizedActionList(ConfPaths.BLOCKPLACE_AGAINST_ACTIONS, Permissions.BLOCKPLACE_AGAINST);
autoSignCheck = data.getBoolean(ConfPaths.BLOCKPLACE_AUTOSIGN_CHECK);
autoSignSkipEmpty = data.getBoolean(ConfPaths.BLOCKPLACE_AUTOSIGN_SKIPEMPTY);
autoSignActions = data.getOptimizedActionList(ConfPaths.BLOCKPLACE_AUTOSIGN_ACTIONS, Permissions.BLOCKPLACE_AUTOSIGN);

View File

@ -192,6 +192,7 @@ public abstract class ConfPaths {
private static final String BLOCKPLACE_AUTOSIGN = BLOCKPLACE + "autosign.";
public static final String BLOCKPLACE_AUTOSIGN_CHECK = BLOCKPLACE_AUTOSIGN + "active";
public static final String BLOCKPLACE_AUTOSIGN_SKIPEMPTY = BLOCKPLACE_AUTOSIGN + "skipempty";
public static final String BLOCKPLACE_AUTOSIGN_ACTIONS = BLOCKPLACE_AUTOSIGN + "actions";
private static final String BLOCKPLACE_DIRECTION = BLOCKPLACE + "direction.";

View File

@ -128,6 +128,7 @@ public class DefaultConfig extends ConfigFile {
set(ConfPaths.BLOCKPLACE_AGAINST_ACTIONS, "cancel");
set(ConfPaths.BLOCKPLACE_AUTOSIGN_CHECK, true);
set(ConfPaths.BLOCKPLACE_AUTOSIGN_SKIPEMPTY, false);
set(ConfPaths.BLOCKPLACE_AUTOSIGN_ACTIONS, "cancel vl>10 log:bautosign:0:3:if cancel");
set(ConfPaths.BLOCKPLACE_DIRECTION_CHECK, true);