diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/CheckType.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/CheckType.java index 42beec38..d00c7e1e 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/CheckType.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/CheckType.java @@ -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_VISIBLE(BLOCKINTERACT, Permissions.BLOCKINTERACT_VISIBLE), BLOCKPLACE(BlockPlaceConfig.factory, BlockPlaceData.factory, Permissions.BLOCKPLACE), BLOCKPLACE_DIRECTION(BLOCKPLACE, Permissions.BLOCKPLACE_DIRECTION), diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractConfig.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractConfig.java index 3fa2a26f..72a77ea3 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractConfig.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractConfig.java @@ -76,6 +76,9 @@ public class BlockInteractConfig extends ACheckConfig { public final boolean reachCheck; public final ActionList reachActions; + + public final boolean visibleCheck; + public final ActionList visibleActions; /** * Instantiates a new block interact configuration. @@ -91,6 +94,9 @@ public class BlockInteractConfig extends ACheckConfig { reachCheck = data.getBoolean(ConfPaths.BLOCKINTERACT_REACH_CHECK); reachActions = data.getOptimizedActionList(ConfPaths.BLOCKINTERACT_REACH_ACTIONS, Permissions.BLOCKINTERACT_REACH); + + visibleCheck = data.getBoolean(ConfPaths.BLOCKINTERACT_VISIBLE_CHECK); + visibleActions = data.getOptimizedActionList(ConfPaths.BLOCKINTERACT_VISIBLE_ACTIONS, Permissions.BLOCKINTERACT_VISIBLE); } /* (non-Javadoc) @@ -103,6 +109,8 @@ public class BlockInteractConfig extends ACheckConfig { return directionCheck; case BLOCKINTERACT_REACH: return reachCheck; + case BLOCKINTERACT_VISIBLE: + return visibleCheck; default: return true; } diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractData.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractData.java index 93f4bad6..c5956981 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractData.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractData.java @@ -74,8 +74,9 @@ public class BlockInteractData extends ACheckData { } // Violation levels. - public double directionVL; - public double reachVL; + public double directionVL = 0; + public double reachVL = 0; + public double visibleVL = 0; // Data of the reach check. public double reachDistance; diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractListener.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractListener.java index 10d574fe..befd3bab 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractListener.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractListener.java @@ -2,6 +2,7 @@ package fr.neatmonster.nocheatplus.checks.blockinteract; import org.bukkit.Location; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.event.Event.Result; import org.bukkit.event.EventHandler; @@ -42,6 +43,9 @@ public class BlockInteractListener extends CheckListener { /** The reach check. */ private final Reach reach = addCheck(new Reach()); + /** The Visible check. */ + private final Visible visible = addCheck(new Visible()); + public BlockInteractListener(){ super(CheckType.BLOCKINTERACT); } @@ -85,6 +89,7 @@ public class BlockInteractListener extends CheckListener { boolean cancelled = false; + final BlockFace face = event.getBlockFace(); final Location loc = player.getLocation(); // TODO: fast-interact ! @@ -99,6 +104,11 @@ public class BlockInteractListener extends CheckListener { cancelled = true; } + // Ray tracing for freecam use etc. + if (!cancelled && visible.isEnabled(player) && visible.check(player, loc, block, face, action, data, cc)){ + cancelled = true; + } + // If one of the checks requested to cancel the event, do so. if (cancelled) { event.setUseInteractedBlock(Result.DENY); diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/Visible.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/Visible.java new file mode 100644 index 00000000..eb16868e --- /dev/null +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/Visible.java @@ -0,0 +1,68 @@ +package fr.neatmonster.nocheatplus.checks.blockinteract; + +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; + +import fr.neatmonster.nocheatplus.checks.Check; +import fr.neatmonster.nocheatplus.checks.CheckType; +import fr.neatmonster.nocheatplus.compat.MCAccess; +import fr.neatmonster.nocheatplus.permissions.Permissions; +import fr.neatmonster.nocheatplus.utilities.BlockCache; +import fr.neatmonster.nocheatplus.utilities.InteractRayTracing; + +public class Visible extends Check { + + private BlockCache blockCache; + + private final InteractRayTracing rayTracing = new InteractRayTracing(false); + + public Visible() { + super(CheckType.BLOCKINTERACT_VISIBLE); + blockCache = mcAccess.getBlockCache(null); + } + + /* (non-Javadoc) + * @see fr.neatmonster.nocheatplus.checks.Check#setMCAccess(fr.neatmonster.nocheatplus.compat.MCAccess) + */ + @Override + public void setMCAccess(MCAccess mcAccess) { + super.setMCAccess(mcAccess); + // Renew the BlockCache instance. + blockCache = mcAccess.getBlockCache(null); + } + + public boolean check(final Player player, final Location loc, final Block block, final BlockFace face, final Action action, final BlockInteractData data, final BlockInteractConfig cc) { + + // TODO: Might confine what to check for (left/right, target blocks depending on item in hand, container blocks). + + blockCache.setAccess(loc.getWorld()); + rayTracing.setBlockCache(blockCache); + rayTracing.set(loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ(), 0.5 + block.getX() + 0.6 * face.getModX(), 0.5 + block.getY() + 0.6 * face.getModY(), 0.5 + block.getZ() + 0.6 * face.getModZ()); + rayTracing.loop(); + final boolean collides = rayTracing.collides(); + blockCache.cleanup(); + rayTracing.cleanup(); + + if (cc.debug && player.hasPermission(Permissions.ADMINISTRATION_DEBUG)){ + player.sendMessage("Interact: " + (action == Action.RIGHT_CLICK_BLOCK ? "right" : "left") + " collide=" + rayTracing.collides()); + } + + // Actions ? + boolean cancel = false; + if (collides){ + data.visibleVL += 1; + if (executeActions(player, data.visibleVL, 1, cc.visibleActions)){ + cancel = true; + } + } + else{ + data.visibleVL *= 0.99; + } + + return cancel; + } + +} diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java index 9dcf603d..3670869a 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -141,6 +141,10 @@ public abstract class ConfPaths { private static final String BLOCKINTERACT_REACH = BLOCKINTERACT + "reach."; 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_VISIBLE = BLOCKINTERACT + "visible."; + public static final String BLOCKINTERACT_VISIBLE_CHECK = BLOCKINTERACT_VISIBLE + "active"; + public static final String BLOCKINTERACT_VISIBLE_ACTIONS = BLOCKINTERACT_VISIBLE + "actions"; /* * 888 88b, 888 888 888 88e 888 diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java index beca2c2b..b26623c6 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -123,7 +123,10 @@ 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_VISIBLE_CHECK, true); + set(ConfPaths.BLOCKINTERACT_VISIBLE_ACTIONS, "cancel vl>5 log:bvisible:0:2:if cancel"); + /* * 888 88b, 888 888 888 88e 888 * 888 88P' 888 e88 88e e88'888 888 ee 888 888D 888 ,"Y88b e88'888 ,e e, @@ -425,9 +428,9 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.STRINGS + ".bdirection", start + "tried to interact with a block out of his line of sight" + end); 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 - + "tried to interact with a block over distance [reachdistance] block(s)" + 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 + ".bvisible", start + "interacts with a block out of sight" + 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); diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/permissions/Permissions.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/permissions/Permissions.java index fcbd5c1d..fba845cc 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/permissions/Permissions.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/permissions/Permissions.java @@ -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_VISIBLE = BLOCKINTERACT + ".visible"; /* * 888 88b, 888 888 888 88e 888 diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/utilities/CheckUtils.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/utilities/CheckUtils.java index 3bb8b3d4..9d4c21f6 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/utilities/CheckUtils.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/utilities/CheckUtils.java @@ -42,6 +42,8 @@ public class CheckUtils { */ public static double directionCheck(final Player player, final double targetX, final double targetY, final double targetZ, final double targetWidth, final double targetHeight, final double precision) { + + // TODO: optimize ! // Get the eye location of the player. final Location eyes = player.getEyeLocation(); diff --git a/NCPPlugin/src/main/resources/plugin.yml b/NCPPlugin/src/main/resources/plugin.yml index 9ccc4908..5cc8de92 100644 --- a/NCPPlugin/src/main/resources/plugin.yml +++ b/NCPPlugin/src/main/resources/plugin.yml @@ -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.visible: + description: Allow the player to bypass the Visible check. nocheatplus.checks.blockplace: description: Allow the player to bypass all BlockPlace checks. children: