mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-11-02 08:40:01 +01:00
Add simple wrong block check to block break.
This commit is contained in:
parent
070bcac0da
commit
f1358ec1a6
@ -41,6 +41,7 @@ public enum CheckType {
|
||||
BLOCKBREAK_FASTBREAK(BLOCKBREAK, Permissions.BLOCKBREAK_FASTBREAK),
|
||||
BLOCKBREAK_NOSWING(BLOCKBREAK, Permissions.BLOCKBREAK_NOSWING),
|
||||
BLOCKBREAK_REACH(BLOCKBREAK, Permissions.BLOCKBREAK_REACH),
|
||||
BLOCKBREAK_WRONGBLOCK(BLOCKBREAK, Permissions.BLOCKBREAK_WRONGBLOCK),
|
||||
|
||||
BLOCKINTERACT(BlockInteractConfig.factory, BlockInteractData.factory),
|
||||
BLOCKINTERACT_DIRECTION(BLOCKINTERACT, Permissions.BLOCKINTERACT_DIRECTION),
|
||||
@ -85,7 +86,7 @@ public enum CheckType {
|
||||
MOVING_MOREPACKETSVEHICLE(MOVING, Permissions.MOVING_MOREPACKETSVEHICLE),
|
||||
MOVING_NOFALL(MOVING, Permissions.MOVING_NOFALL),
|
||||
MOVING_SURVIVALFLY(MOVING, Permissions.MOVING_SURVIVALFLY),
|
||||
|
||||
|
||||
UNKNOWN;
|
||||
|
||||
/** The group. */
|
||||
|
@ -87,6 +87,10 @@ public class BlockBreakConfig extends ACheckConfig {
|
||||
public final boolean reachCheck;
|
||||
public final ActionList reachActions;
|
||||
|
||||
|
||||
public final boolean wrongBlockCheck;
|
||||
public final ActionList wrongBlockActions;
|
||||
|
||||
/**
|
||||
* Instantiates a new block break configuration.
|
||||
*
|
||||
@ -109,6 +113,9 @@ public class BlockBreakConfig extends ACheckConfig {
|
||||
|
||||
reachCheck = data.getBoolean(ConfPaths.BLOCKBREAK_REACH_CHECK);
|
||||
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)
|
||||
@ -125,6 +132,8 @@ public class BlockBreakConfig extends ACheckConfig {
|
||||
return noSwingCheck;
|
||||
case BLOCKBREAK_REACH:
|
||||
return reachCheck;
|
||||
case BLOCKBREAK_WRONGBLOCK:
|
||||
return wrongBlockCheck;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
|
@ -60,6 +60,12 @@ public class BlockBreakData extends ACheckData {
|
||||
public double fastBreakVL;
|
||||
public double noSwingVL;
|
||||
public double reachVL;
|
||||
public double wrongBlockVL;
|
||||
|
||||
// Shared data.
|
||||
public int clickedX;
|
||||
public int clickedY;
|
||||
public int clickedZ;
|
||||
|
||||
// Data of the fast break check.
|
||||
public int fastBreakBuffer = 5;
|
||||
|
@ -44,6 +44,9 @@ public class BlockBreakListener implements Listener {
|
||||
|
||||
/** The reach check. */
|
||||
private final Reach reach = new Reach();
|
||||
|
||||
/** The wrong block check. */
|
||||
private final WrongBlock wrongBlock = new WrongBlock();
|
||||
|
||||
/**
|
||||
* 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
|
||||
// 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?
|
||||
if (fastBreak.isEnabled(player) && fastBreak.check(player, block))
|
||||
cancelled = true;
|
||||
@ -131,9 +138,19 @@ public class BlockBreakListener implements Listener {
|
||||
* |___/
|
||||
*/
|
||||
// Do not care about null blocks.
|
||||
if (event.getClickedBlock() == null)
|
||||
final Block block = event.getClickedBlock();
|
||||
if (block == null)
|
||||
return;
|
||||
|
||||
BlockBreakData.getData(event.getPlayer()).fastBreakDamageTime = System.currentTimeMillis();
|
||||
final BlockBreakData data = BlockBreakData.getData(event.getPlayer());
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -78,6 +78,10 @@ public abstract class ConfPaths {
|
||||
private static final String BLOCKBREAK_REACH = BLOCKBREAK + "reach.";
|
||||
public static final String BLOCKBREAK_REACH_CHECK = BLOCKBREAK_REACH + "active";
|
||||
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
|
||||
@ -257,7 +261,7 @@ public abstract class ConfPaths {
|
||||
public static final String COMBINED_IMPROBABLE_CHECK = COMBINED_IMPROBABLE + "active";
|
||||
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_ACTIONS = COMBINED_IMPROBABLE + "actions";
|
||||
|
@ -78,7 +78,10 @@ public class DefaultConfig extends ConfigFile {
|
||||
|
||||
set(ConfPaths.BLOCKBREAK_REACH_CHECK, true);
|
||||
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 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_LEVEL, 300);
|
||||
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
|
||||
@ -340,6 +343,7 @@ public class DefaultConfig extends ConfigFile {
|
||||
set(ConfPaths.STRINGS + ".bpspeed", start + "tried to throw projectiles too quickly" + end);
|
||||
set(ConfPaths.STRINGS + ".breach", start
|
||||
+ "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 + ".color", start + "sent colored chat message" + 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 + ".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 + ".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 + ".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);
|
||||
|
@ -51,6 +51,7 @@ public class Permissions {
|
||||
public static final String BLOCKBREAK_FASTBREAK = BLOCKBREAK + ".fastbreak";
|
||||
public static final String BLOCKBREAK_NOSWING = BLOCKBREAK + ".noswing";
|
||||
public static final String BLOCKBREAK_REACH = BLOCKBREAK + ".reach";
|
||||
public static final String BLOCKBREAK_WRONGBLOCK = BLOCKBREAK + ".wrongblock";
|
||||
|
||||
/*
|
||||
* 888 88b, 888 888 888 d8 d8
|
||||
|
Loading…
Reference in New Issue
Block a user