Add simple wrong block check to block break.

This commit is contained in:
asofold 2012-09-10 12:39:29 +02:00
parent 070bcac0da
commit f1358ec1a6
8 changed files with 82 additions and 7 deletions

View File

@ -41,6 +41,7 @@ public enum CheckType {
BLOCKBREAK_FASTBREAK(BLOCKBREAK, Permissions.BLOCKBREAK_FASTBREAK), BLOCKBREAK_FASTBREAK(BLOCKBREAK, Permissions.BLOCKBREAK_FASTBREAK),
BLOCKBREAK_NOSWING(BLOCKBREAK, Permissions.BLOCKBREAK_NOSWING), BLOCKBREAK_NOSWING(BLOCKBREAK, Permissions.BLOCKBREAK_NOSWING),
BLOCKBREAK_REACH(BLOCKBREAK, Permissions.BLOCKBREAK_REACH), BLOCKBREAK_REACH(BLOCKBREAK, Permissions.BLOCKBREAK_REACH),
BLOCKBREAK_WRONGBLOCK(BLOCKBREAK, Permissions.BLOCKBREAK_WRONGBLOCK),
BLOCKINTERACT(BlockInteractConfig.factory, BlockInteractData.factory), BLOCKINTERACT(BlockInteractConfig.factory, BlockInteractData.factory),
BLOCKINTERACT_DIRECTION(BLOCKINTERACT, Permissions.BLOCKINTERACT_DIRECTION), BLOCKINTERACT_DIRECTION(BLOCKINTERACT, Permissions.BLOCKINTERACT_DIRECTION),

View File

@ -87,6 +87,10 @@ public class BlockBreakConfig extends ACheckConfig {
public final boolean reachCheck; public final boolean reachCheck;
public final ActionList reachActions; public final ActionList reachActions;
public final boolean wrongBlockCheck;
public final ActionList wrongBlockActions;
/** /**
* Instantiates a new block break configuration. * Instantiates a new block break configuration.
* *
@ -109,6 +113,9 @@ public class BlockBreakConfig extends ACheckConfig {
reachCheck = data.getBoolean(ConfPaths.BLOCKBREAK_REACH_CHECK); reachCheck = data.getBoolean(ConfPaths.BLOCKBREAK_REACH_CHECK);
reachActions = data.getActionList(ConfPaths.BLOCKBREAK_REACH_ACTIONS, Permissions.BLOCKBREAK_REACH); reachActions = data.getActionList(ConfPaths.BLOCKBREAK_REACH_ACTIONS, Permissions.BLOCKBREAK_REACH);
wrongBlockCheck = data.getBoolean(ConfPaths.BLOCKBREAK_WRONGBLOCK_CHECK);
wrongBlockActions = data.getActionList(ConfPaths.BLOCKBREAK_WRONGBLOCK_ACTIONS, Permissions.BLOCKBREAK_WRONGBLOCK);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -125,6 +132,8 @@ public class BlockBreakConfig extends ACheckConfig {
return noSwingCheck; return noSwingCheck;
case BLOCKBREAK_REACH: case BLOCKBREAK_REACH:
return reachCheck; return reachCheck;
case BLOCKBREAK_WRONGBLOCK:
return wrongBlockCheck;
default: default:
return true; return true;
} }

View File

@ -60,6 +60,12 @@ public class BlockBreakData extends ACheckData {
public double fastBreakVL; public double fastBreakVL;
public double noSwingVL; public double noSwingVL;
public double reachVL; public double reachVL;
public double wrongBlockVL;
// Shared data.
public int clickedX;
public int clickedY;
public int clickedZ;
// Data of the fast break check. // Data of the fast break check.
public int fastBreakBuffer = 5; public int fastBreakBuffer = 5;

View File

@ -45,6 +45,9 @@ public class BlockBreakListener implements Listener {
/** The reach check. */ /** The reach check. */
private final Reach reach = new Reach(); private final Reach reach = new Reach();
/** The wrong block check. */
private final WrongBlock wrongBlock = new WrongBlock();
/** /**
* We listen to BlockBreak events for obvious reasons. * We listen to BlockBreak events for obvious reasons.
* *
@ -69,6 +72,10 @@ public class BlockBreakListener implements Listener {
// Do the actual checks, if still needed. It's a good idea to make computationally cheap checks first, because // Do the actual checks, if still needed. It's a good idea to make computationally cheap checks first, because
// it may save us from doing the computationally expensive checks. // it may save us from doing the computationally expensive checks.
// Has the player broken a block that was not damaged before?
if (wrongBlock.isEnabled(player) && wrongBlock.check(player, block))
cancelled = true;
// Has the player broken blocks too quickly? // Has the player broken blocks too quickly?
if (fastBreak.isEnabled(player) && fastBreak.check(player, block)) if (fastBreak.isEnabled(player) && fastBreak.check(player, block))
cancelled = true; cancelled = true;
@ -131,9 +138,19 @@ public class BlockBreakListener implements Listener {
* |___/ * |___/
*/ */
// Do not care about null blocks. // Do not care about null blocks.
if (event.getClickedBlock() == null) final Block block = event.getClickedBlock();
if (block == null)
return; return;
final BlockBreakData data = BlockBreakData.getData(event.getPlayer());
BlockBreakData.getData(event.getPlayer()).fastBreakDamageTime = System.currentTimeMillis(); data.fastBreakDamageTime = System.currentTimeMillis();
// Also set last clicked blocks position.
// ? only set time / block, if
// - action = left_click_block
// - time not already set => design to really record the used time.
// DRAWBACK: lag, thus: rather switch to accumulate the theoretically needed break times in an ActionFrequency buffer,
// then use those to determine if to prevent or not, depending on settings + lag.
data.clickedX = block.getX();
data.clickedY = block.getY();
data.clickedZ = block.getZ();
} }
} }

View File

@ -0,0 +1,32 @@
package fr.neatmonster.nocheatplus.checks.blockbreak;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.combined.Improbable;
public class WrongBlock extends Check {
public WrongBlock() {
super(CheckType.BLOCKBREAK_WRONGBLOCK);
}
public boolean check(final Player player, final Block block){
final BlockBreakConfig cc = BlockBreakConfig.getConfig(player);
final BlockBreakData data = BlockBreakData.getData(player);
boolean cancel = false;
if (data.clickedX != block.getX() || data.clickedZ != block.getZ() || data.clickedY != block.getY()){
data.wrongBlockVL += 1D;
if (executeActions(player, data.wrongBlockVL, 1D, cc.wrongBlockActions))
cancel = true;
if (Improbable.check(player, 5.0f, System.currentTimeMillis()))
cancel = true;
}
return cancel;
}
}

View File

@ -79,6 +79,10 @@ public abstract class ConfPaths {
public static final String BLOCKBREAK_REACH_CHECK = BLOCKBREAK_REACH + "active"; public static final String BLOCKBREAK_REACH_CHECK = BLOCKBREAK_REACH + "active";
public static final String BLOCKBREAK_REACH_ACTIONS = BLOCKBREAK_REACH + "actions"; public static final String BLOCKBREAK_REACH_ACTIONS = BLOCKBREAK_REACH + "actions";
private static final String BLOCKBREAK_WRONGBLOCK = BLOCKBREAK + "wrongblock.";
public static final String BLOCKBREAK_WRONGBLOCK_CHECK = BLOCKBREAK_WRONGBLOCK + "active";
public static final String BLOCKBREAK_WRONGBLOCK_ACTIONS = BLOCKBREAK_WRONGBLOCK + "actions";
/* /*
* 888 88b, 888 888 888 d8 d8 * 888 88b, 888 888 888 d8 d8
* 888 88P' 888 e88 88e e88'888 888 ee 888 888 8e d88 ,e e, 888,8, ,"Y88b e88'888 d88 * 888 88P' 888 e88 88e e88'888 888 ee 888 888 8e d88 ,e e, 888,8, ,"Y88b e88'888 d88
@ -257,7 +261,7 @@ public abstract class ConfPaths {
public static final String COMBINED_IMPROBABLE_CHECK = COMBINED_IMPROBABLE + "active"; public static final String COMBINED_IMPROBABLE_CHECK = COMBINED_IMPROBABLE + "active";
public static final String COMBINED_IMPROBABLE_LEVEL = COMBINED_IMPROBABLE + "level"; public static final String COMBINED_IMPROBABLE_LEVEL = COMBINED_IMPROBABLE + "level";
private static final String COMBINED_IMPROBABLE_CHECKS = COMBINED_IMPROBABLE + "checks."; private static final String COMBINED_IMPROBABLE_CHECKS = COMBINED_IMPROBABLE + "options.";
public static final String COMBINED_IMPROBABLE_FASTBREAK_CHECK = COMBINED_IMPROBABLE_CHECKS + "fastbreak"; public static final String COMBINED_IMPROBABLE_FASTBREAK_CHECK = COMBINED_IMPROBABLE_CHECKS + "fastbreak";
public static final String COMBINED_IMPROBABLE_ACTIONS = COMBINED_IMPROBABLE + "actions"; public static final String COMBINED_IMPROBABLE_ACTIONS = COMBINED_IMPROBABLE + "actions";

View File

@ -79,6 +79,9 @@ public class DefaultConfig extends ConfigFile {
set(ConfPaths.BLOCKBREAK_REACH_CHECK, true); set(ConfPaths.BLOCKBREAK_REACH_CHECK, true);
set(ConfPaths.BLOCKBREAK_REACH_ACTIONS, "cancel vl>5 log:breach:0:2:if cancel"); set(ConfPaths.BLOCKBREAK_REACH_ACTIONS, "cancel vl>5 log:breach:0:2:if cancel");
set(ConfPaths.BLOCKBREAK_WRONGBLOCK_CHECK, true);
set(ConfPaths.BLOCKBREAK_WRONGBLOCK_ACTIONS, "log:bwrong:0:5:if cancel vl>20 log:bwrong:0:5:if cancel cmd:kickwb");
/* /*
* 888 88b, 888 888 888 d8 d8 * 888 88b, 888 888 888 d8 d8
* 888 88P' 888 e88 88e e88'888 888 ee 888 888 8e d88 ,e e, 888,8, ,"Y88b e88'888 d88 * 888 88P' 888 e88 88e e88'888 888 ee 888 888 8e d88 ,e e, 888,8, ,"Y88b e88'888 d88
@ -212,7 +215,7 @@ public class DefaultConfig extends ConfigFile {
set(ConfPaths.COMBINED_IMPROBABLE_CHECK , false); set(ConfPaths.COMBINED_IMPROBABLE_CHECK , false);
set(ConfPaths.COMBINED_IMPROBABLE_LEVEL, 300); set(ConfPaths.COMBINED_IMPROBABLE_LEVEL, 300);
set(ConfPaths.COMBINED_IMPROBABLE_FASTBREAK_CHECK, false); set(ConfPaths.COMBINED_IMPROBABLE_FASTBREAK_CHECK, false);
set(ConfPaths.COMBINED_IMPROBABLE_ACTIONS, "cancel log:improbable:2:5:if"); set(ConfPaths.COMBINED_IMPROBABLE_ACTIONS, "cancel log:improbable:2:8:if");
/* /*
* 888'Y88 ,e, 888 d8 * 888'Y88 ,e, 888 d8
@ -340,6 +343,7 @@ public class DefaultConfig extends ConfigFile {
set(ConfPaths.STRINGS + ".bpspeed", start + "tried to throw projectiles too quickly" + end); set(ConfPaths.STRINGS + ".bpspeed", start + "tried to throw projectiles too quickly" + end);
set(ConfPaths.STRINGS + ".breach", start set(ConfPaths.STRINGS + ".breach", start
+ "tried to interact with a block over distance [reachdistance] block(s)" + end); + "tried to interact with a block over distance [reachdistance] block(s)" + end);
set(ConfPaths.STRINGS + ".bwrong", start + "broke another block than clicked" + end);
set(ConfPaths.STRINGS + ".captcha", "[player] failed captcha repeatedly" + end); set(ConfPaths.STRINGS + ".captcha", "[player] failed captcha repeatedly" + end);
set(ConfPaths.STRINGS + ".color", start + "sent colored chat message" + end); set(ConfPaths.STRINGS + ".color", start + "sent colored chat message" + end);
set(ConfPaths.STRINGS + ".combspeed", start + "performs different actions at very high speed" + end); set(ConfPaths.STRINGS + ".combspeed", start + "performs different actions at very high speed" + end);
@ -366,6 +370,7 @@ public class DefaultConfig extends ConfigFile {
set(ConfPaths.STRINGS + ".kickcaptcha", "ncp kick [player] Enter the captcha!"); set(ConfPaths.STRINGS + ".kickcaptcha", "ncp kick [player] Enter the captcha!");
set(ConfPaths.STRINGS + ".kickglchat", "ncp kick [player] Too many chat messages, take a break."); set(ConfPaths.STRINGS + ".kickglchat", "ncp kick [player] Too many chat messages, take a break.");
set(ConfPaths.STRINGS + ".kickselfhit", "ncp kick [player] That must be exhausting!"); set(ConfPaths.STRINGS + ".kickselfhit", "ncp kick [player] That must be exhausting!");
set(ConfPaths.STRINGS + ".kickwb", "ncp kick [player] Wrong block!");
set(ConfPaths.STRINGS + ".knockback", start + "tried to do a knockback but wasn't technically sprinting" + end); set(ConfPaths.STRINGS + ".knockback", start + "tried to do a knockback but wasn't technically sprinting" + end);
set(ConfPaths.STRINGS + ".morepackets", start + "sent [packets] more packet(s) than expected" + end); set(ConfPaths.STRINGS + ".morepackets", start + "sent [packets] more packet(s) than expected" + end);
set(ConfPaths.STRINGS + ".nofall", start + "tried to avoid fall damage for ~[falldistance] block(s)" + end); set(ConfPaths.STRINGS + ".nofall", start + "tried to avoid fall damage for ~[falldistance] block(s)" + end);

View File

@ -51,6 +51,7 @@ public class Permissions {
public static final String BLOCKBREAK_FASTBREAK = BLOCKBREAK + ".fastbreak"; public static final String BLOCKBREAK_FASTBREAK = BLOCKBREAK + ".fastbreak";
public static final String BLOCKBREAK_NOSWING = BLOCKBREAK + ".noswing"; public static final String BLOCKBREAK_NOSWING = BLOCKBREAK + ".noswing";
public static final String BLOCKBREAK_REACH = BLOCKBREAK + ".reach"; public static final String BLOCKBREAK_REACH = BLOCKBREAK + ".reach";
public static final String BLOCKBREAK_WRONGBLOCK = BLOCKBREAK + ".wrongblock";
/* /*
* 888 88b, 888 888 888 d8 d8 * 888 88b, 888 888 888 d8 d8