mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-13 19:11:22 +01:00
[Bleeding] Add interact.speed check.
This commit is contained in:
parent
dd5f094472
commit
6112d5b9fb
@ -50,6 +50,7 @@ public enum CheckType {
|
||||
BLOCKINTERACT(BlockInteractConfig.factory, BlockInteractData.factory, Permissions.BLOCKINTERACT),
|
||||
BLOCKINTERACT_DIRECTION(BLOCKINTERACT, Permissions.BLOCKINTERACT_DIRECTION),
|
||||
BLOCKINTERACT_REACH(BLOCKINTERACT, Permissions.BLOCKINTERACT_REACH),
|
||||
BLOCKINTERACT_SPEED(BLOCKINTERACT, Permissions.BLOCKINTERACT_SPEED),
|
||||
BLOCKINTERACT_VISIBLE(BLOCKINTERACT, Permissions.BLOCKINTERACT_VISIBLE),
|
||||
|
||||
BLOCKPLACE(BlockPlaceConfig.factory, BlockPlaceData.factory, Permissions.BLOCKPLACE),
|
||||
|
@ -77,6 +77,11 @@ public class BlockInteractConfig extends ACheckConfig {
|
||||
public final boolean reachCheck;
|
||||
public final ActionList reachActions;
|
||||
|
||||
public final boolean speedCheck;
|
||||
public final long speedInterval;
|
||||
public final int speedLimit;
|
||||
public final ActionList speedActions;
|
||||
|
||||
public final boolean visibleCheck;
|
||||
public final ActionList visibleActions;
|
||||
|
||||
@ -95,6 +100,11 @@ public class BlockInteractConfig extends ACheckConfig {
|
||||
reachCheck = data.getBoolean(ConfPaths.BLOCKINTERACT_REACH_CHECK);
|
||||
reachActions = data.getOptimizedActionList(ConfPaths.BLOCKINTERACT_REACH_ACTIONS, Permissions.BLOCKINTERACT_REACH);
|
||||
|
||||
speedCheck = data.getBoolean(ConfPaths.BLOCKINTERACT_SPEED_CHECK);
|
||||
speedInterval = data.getLong(ConfPaths.BLOCKINTERACT_SPEED_INTERVAL);
|
||||
speedLimit = data.getInt(ConfPaths.BLOCKINTERACT_SPEED_LIMIT);
|
||||
speedActions = data.getOptimizedActionList(ConfPaths.BLOCKINTERACT_SPEED_ACTIONS, Permissions.BLOCKINTERACT_SPEED);
|
||||
|
||||
visibleCheck = data.getBoolean(ConfPaths.BLOCKINTERACT_VISIBLE_CHECK);
|
||||
visibleActions = data.getOptimizedActionList(ConfPaths.BLOCKINTERACT_VISIBLE_ACTIONS, Permissions.BLOCKINTERACT_VISIBLE);
|
||||
}
|
||||
@ -105,6 +115,8 @@ public class BlockInteractConfig extends ACheckConfig {
|
||||
@Override
|
||||
public final boolean isEnabled(final CheckType checkType) {
|
||||
switch (checkType) {
|
||||
case BLOCKINTERACT_SPEED:
|
||||
return speedCheck;
|
||||
case BLOCKINTERACT_DIRECTION:
|
||||
return directionCheck;
|
||||
case BLOCKINTERACT_REACH:
|
||||
|
@ -76,8 +76,15 @@ public class BlockInteractData extends ACheckData {
|
||||
// Violation levels.
|
||||
public double directionVL = 0;
|
||||
public double reachVL = 0;
|
||||
public double speedVL = 0;
|
||||
public double visibleVL = 0;
|
||||
|
||||
// Data of the reach check.
|
||||
public double reachDistance;
|
||||
|
||||
/** Last reset time. */
|
||||
public long speedTime = 0;
|
||||
/** Number of interactions since last reset-time. */
|
||||
public int speedCount = 0;
|
||||
|
||||
}
|
||||
|
@ -37,15 +37,18 @@ import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
*/
|
||||
public class BlockInteractListener extends CheckListener {
|
||||
|
||||
/** The direction check. */
|
||||
/** The looking-direction check. */
|
||||
private final Direction direction = addCheck(new Direction());
|
||||
|
||||
/** The reach check. */
|
||||
/** The reach-distance check. */
|
||||
private final Reach reach = addCheck(new Reach());
|
||||
|
||||
/** The Visible check. */
|
||||
/** Interact with visible blocks. */
|
||||
private final Visible visible = addCheck(new Visible());
|
||||
|
||||
/** Speed of interaction. */
|
||||
private final Speed speed = addCheck(new Speed());
|
||||
|
||||
public BlockInteractListener(){
|
||||
super(CheckType.BLOCKINTERACT);
|
||||
}
|
||||
@ -92,7 +95,10 @@ public class BlockInteractListener extends CheckListener {
|
||||
final BlockFace face = event.getBlockFace();
|
||||
final Location loc = player.getLocation();
|
||||
|
||||
// TODO: fast-interact !
|
||||
// Interaction speed.
|
||||
if (!cancelled && speed.isEnabled(player) && speed.check(player, data, cc)){
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
// First the reach check.
|
||||
if (!cancelled && reach.isEnabled(player) && reach.check(player, loc, block, data, cc)){
|
||||
|
@ -0,0 +1,51 @@
|
||||
package fr.neatmonster.nocheatplus.checks.blockinteract;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.permissions.Permissions;
|
||||
import fr.neatmonster.nocheatplus.utilities.TickTask;
|
||||
|
||||
public class Speed extends Check {
|
||||
|
||||
public Speed() {
|
||||
super(CheckType.BLOCKINTERACT_SPEED);
|
||||
}
|
||||
|
||||
public boolean check(final Player player, final BlockInteractData data, final BlockInteractConfig cc){
|
||||
|
||||
final long time = System.currentTimeMillis();
|
||||
|
||||
if (time < data.speedTime || time > data.speedTime + cc.speedInterval){
|
||||
data.speedTime = time;
|
||||
data.speedCount = 0;
|
||||
}
|
||||
|
||||
// Increase count.
|
||||
data.speedCount ++;
|
||||
|
||||
boolean cancel = false;
|
||||
|
||||
if (data.speedCount > cc.speedLimit){
|
||||
// Lag correction
|
||||
final int correctedCount = (int) ((double) data.speedCount / TickTask.getLag(time - data.speedTime));
|
||||
if (correctedCount > cc.speedLimit){
|
||||
if (executeActions(player, data.speedVL, 1, cc.speedActions)){
|
||||
cancel = true;
|
||||
}
|
||||
}
|
||||
// else: keep vl.
|
||||
}
|
||||
else{
|
||||
data.speedVL *= 0.99;
|
||||
}
|
||||
|
||||
if (cc.debug && player.hasPermission(Permissions.ADMINISTRATION_DEBUG)){
|
||||
player.sendMessage("Interact speed: " + data.speedCount);
|
||||
}
|
||||
|
||||
return cancel;
|
||||
}
|
||||
|
||||
}
|
@ -142,6 +142,12 @@ public abstract class ConfPaths {
|
||||
public static final String BLOCKINTERACT_REACH_CHECK = BLOCKINTERACT_REACH + "active";
|
||||
public static final String BLOCKINTERACT_REACH_ACTIONS = BLOCKINTERACT_REACH + "actions";
|
||||
|
||||
private static final String BLOCKINTERACT_SPEED = BLOCKINTERACT + "speed.";
|
||||
public static final String BLOCKINTERACT_SPEED_CHECK = BLOCKINTERACT_SPEED + "active";
|
||||
public static final String BLOCKINTERACT_SPEED_INTERVAL = BLOCKINTERACT_SPEED + "interval";
|
||||
public static final String BLOCKINTERACT_SPEED_LIMIT = BLOCKINTERACT_SPEED + "limit";
|
||||
public static final String BLOCKINTERACT_SPEED_ACTIONS = BLOCKINTERACT_SPEED + "actions";
|
||||
|
||||
private static final String BLOCKINTERACT_VISIBLE = BLOCKINTERACT + "visible.";
|
||||
public static final String BLOCKINTERACT_VISIBLE_CHECK = BLOCKINTERACT_VISIBLE + "active";
|
||||
public static final String BLOCKINTERACT_VISIBLE_ACTIONS = BLOCKINTERACT_VISIBLE + "actions";
|
||||
|
@ -124,6 +124,11 @@ public class DefaultConfig extends ConfigFile {
|
||||
set(ConfPaths.BLOCKINTERACT_REACH_CHECK, true);
|
||||
set(ConfPaths.BLOCKINTERACT_REACH_ACTIONS, "cancel vl>5 log:breach:0:2:if cancel");
|
||||
|
||||
set(ConfPaths.BLOCKINTERACT_SPEED_CHECK, true);
|
||||
set(ConfPaths.BLOCKINTERACT_SPEED_INTERVAL, 2000);
|
||||
set(ConfPaths.BLOCKINTERACT_SPEED_LIMIT, 82);
|
||||
set(ConfPaths.BLOCKINTERACT_SPEED_ACTIONS, "cancel vl>200 log:bspeed:0:2:if cancel vl>1000 cancel log:bspeed:0:2:icf cmd:kickbspeed");
|
||||
|
||||
set(ConfPaths.BLOCKINTERACT_VISIBLE_CHECK, true);
|
||||
set(ConfPaths.BLOCKINTERACT_VISIBLE_ACTIONS, "cancel vl>5 log:bvisible:0:2:if cancel");
|
||||
|
||||
@ -429,8 +434,9 @@ public class DefaultConfig extends ConfigFile {
|
||||
set(ConfPaths.STRINGS + ".bedleave", start + "sends bed leave packets (was not in bed)" + end);
|
||||
set(ConfPaths.STRINGS + ".bpspeed", start + "tried to throw projectiles too quickly" + end);
|
||||
set(ConfPaths.STRINGS + ".breach", start + "exceeds block-interact distance ([reachdistance])" + end);
|
||||
set(ConfPaths.STRINGS + ".bwrong", start + "broke another block than clicked" + end);
|
||||
set(ConfPaths.STRINGS + ".bspeed", start + "interacts too fast" + end);
|
||||
set(ConfPaths.STRINGS + ".bvisible", start + "interacts with a block out of sight" + 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 + ".commands", start + "issued too many commands" + end);
|
||||
@ -455,6 +461,7 @@ public class DefaultConfig extends ConfigFile {
|
||||
set(ConfPaths.STRINGS + ".instanteat", start + "eats food [food] too fast" + end);
|
||||
set(ConfPaths.STRINGS + ".kick", "kick [player]");
|
||||
set(ConfPaths.STRINGS + ".kickbedleave", "ncp delay ncp kick [player] Go find a bed!");
|
||||
set(ConfPaths.STRINGS + ".kickbspeed", "ncp kick [player] Too fast interaction!");
|
||||
set(ConfPaths.STRINGS + ".kickcaptcha", "ncp kick [player] Enter the captcha!");
|
||||
set(ConfPaths.STRINGS + ".kickchat1", "ncp tempkick [player] 1 You're still not allowed to spam!");
|
||||
set(ConfPaths.STRINGS + ".kickchat5", "ncp tempkick [player] 5 You're not intended to spam!");
|
||||
|
@ -83,6 +83,7 @@ public class Permissions {
|
||||
public static final String BLOCKINTERACT = CHECKS + ".blockinteract";
|
||||
public static final String BLOCKINTERACT_DIRECTION = BLOCKINTERACT + ".direction";
|
||||
public static final String BLOCKINTERACT_REACH = BLOCKINTERACT + ".reach";
|
||||
public static final String BLOCKINTERACT_SPEED = BLOCKINTERACT + ".speed";
|
||||
public static final String BLOCKINTERACT_VISIBLE = BLOCKINTERACT + ".visible";
|
||||
|
||||
/*
|
||||
|
@ -103,6 +103,8 @@ permissions:
|
||||
description: Allow the player to bypass to Direction check.
|
||||
nocheatplus.checks.blockinteract.reach:
|
||||
description: Allow the player to bypass the Reach check.
|
||||
nocheatplus.checks.blockinteract.speed:
|
||||
description: Allow the player to bypass the Speed check.
|
||||
nocheatplus.checks.blockinteract.visible:
|
||||
description: Allow the player to bypass the Visible check.
|
||||
nocheatplus.checks.blockplace:
|
||||
|
Loading…
Reference in New Issue
Block a user