diff --git a/src/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakListener.java b/src/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakListener.java index 198d57d8..c7b69af2 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakListener.java @@ -75,34 +75,48 @@ 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. - + + final BlockBreakConfig cc = BlockBreakConfig.getConfig(player); + final BlockBreakData data = BlockBreakData.getData(player); + final long now = System.currentTimeMillis(); + // Has the player broken a block that was not damaged before? - if (wrongBlock.isEnabled(player) && wrongBlock.check(player, block)) + if (wrongBlock.isEnabled(player) && wrongBlock.check(player, block, cc, data)) cancelled = true; // Has the player broken more blocks per second than allowed? - if (!cancelled && frequency.isEnabled(player) && frequency.check(player)) + if (!cancelled && frequency.isEnabled(player) && frequency.check(player, cc, data)) cancelled = true; // Has the player broken blocks faster than possible? - if (!cancelled && fastBreak.isEnabled(player) && fastBreak.check(player, block)) + if (!cancelled && fastBreak.isEnabled(player) && fastBreak.check(player, block, cc, data)) cancelled = true; // Did the arm of the player move before breaking this block? - if (!cancelled && noSwing.isEnabled(player) && noSwing.check(player)) + if (!cancelled && noSwing.isEnabled(player) && noSwing.check(player, data)) cancelled = true; // Is the block really in reach distance? - if (!cancelled && reach.isEnabled(player) && reach.check(player, block.getLocation())) + if (!cancelled && reach.isEnabled(player) && reach.check(player, block.getLocation(), data)) cancelled = true; // Did the player look at the block at all? - if (!cancelled && direction.isEnabled(player) && direction.check(player, block.getLocation())) + if (!cancelled && direction.isEnabled(player) && direction.check(player, block.getLocation(), data)) cancelled = true; // At least one check failed and demanded to cancel the event. - if (cancelled) - event.setCancelled(cancelled); + if (cancelled){ + event.setCancelled(cancelled); + // Reset damage position: + data.fastBreakDamageTime = now; + data.clickedX = block.getX(); + data.clickedY = block.getY(); + data.clickedZ = block.getZ(); + } + else{ + // Invalidate last damage position: + data.clickedX = Integer.MAX_VALUE; + } } diff --git a/src/fr/neatmonster/nocheatplus/checks/blockbreak/Direction.java b/src/fr/neatmonster/nocheatplus/checks/blockbreak/Direction.java index 7f255401..3787293a 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockbreak/Direction.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockbreak/Direction.java @@ -38,8 +38,7 @@ public class Direction extends Check { * the location * @return true, if successful */ - public boolean check(final Player player, final Location location) { - final BlockBreakData data = BlockBreakData.getData(player); + public boolean check(final Player player, final Location location, final BlockBreakData data) { boolean cancel = false; diff --git a/src/fr/neatmonster/nocheatplus/checks/blockbreak/FastBreak.java b/src/fr/neatmonster/nocheatplus/checks/blockbreak/FastBreak.java index dc308e9a..bcd29e08 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockbreak/FastBreak.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockbreak/FastBreak.java @@ -38,13 +38,13 @@ public class FastBreak extends Check { * the player * @param block * the block + * @param data + * @param cc * @param elaspedTime * @return true, if successful */ - public boolean check(final Player player, final Block block) { + public boolean check(final Player player, final Block block, final BlockBreakConfig cc, final BlockBreakData data) { final long now = System.currentTimeMillis(); - final BlockBreakConfig cc = BlockBreakConfig.getConfig(player); - final BlockBreakData data = BlockBreakData.getData(player); boolean cancel = false; diff --git a/src/fr/neatmonster/nocheatplus/checks/blockbreak/Frequency.java b/src/fr/neatmonster/nocheatplus/checks/blockbreak/Frequency.java index 4d285f5b..5cecf3a8 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockbreak/Frequency.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockbreak/Frequency.java @@ -17,9 +17,7 @@ public class Frequency extends Check { super(CheckType.BLOCKBREAK_FREQUENCY); } - public boolean check(final Player player){ - final BlockBreakConfig cc = BlockBreakConfig.getConfig(player); - final BlockBreakData data = BlockBreakData.getData(player); + public boolean check(final Player player, final BlockBreakConfig cc, final BlockBreakData data){ final float interval = (float) ((player.getGameMode() == GameMode.CREATIVE)?(cc.frequencyIntervalCreative):(cc.frequencyIntervalSurvival)); data.frequencyBuckets.add(System.currentTimeMillis(), interval); diff --git a/src/fr/neatmonster/nocheatplus/checks/blockbreak/NoSwing.java b/src/fr/neatmonster/nocheatplus/checks/blockbreak/NoSwing.java index 1fea9778..c1bc1656 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockbreak/NoSwing.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockbreak/NoSwing.java @@ -34,8 +34,7 @@ public class NoSwing extends Check { * the player * @return true, if successful */ - public boolean check(final Player player) { - final BlockBreakData data = BlockBreakData.getData(player); + public boolean check(final Player player, final BlockBreakData data) { boolean cancel = false; diff --git a/src/fr/neatmonster/nocheatplus/checks/blockbreak/Reach.java b/src/fr/neatmonster/nocheatplus/checks/blockbreak/Reach.java index 31b5abaa..11a56986 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockbreak/Reach.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockbreak/Reach.java @@ -47,8 +47,7 @@ public class Reach extends Check { * the location * @return true, if successful */ - public boolean check(final Player player, final Location location) { - final BlockBreakData data = BlockBreakData.getData(player); + public boolean check(final Player player, final Location location, final BlockBreakData data) { boolean cancel = false; diff --git a/src/fr/neatmonster/nocheatplus/checks/blockbreak/WrongBlock.java b/src/fr/neatmonster/nocheatplus/checks/blockbreak/WrongBlock.java index 548cc843..fc326178 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockbreak/WrongBlock.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockbreak/WrongBlock.java @@ -19,11 +19,11 @@ public class WrongBlock extends Check { * probably due to packet delaying issues for insta breaking. very effective against some nuker techniques. * @param player * @param block + * @param data + * @param cc * @return */ - public boolean check(final Player player, final Block block){ - final BlockBreakConfig cc = BlockBreakConfig.getConfig(player); - final BlockBreakData data = BlockBreakData.getData(player); + public boolean check(final Player player, final Block block, final BlockBreakConfig cc, final BlockBreakData data){ boolean cancel = false; if (data.clickedX != block.getX() || data.clickedZ != block.getZ() || data.clickedY != block.getY()){ @@ -33,11 +33,6 @@ public class WrongBlock extends Check { cancel = true; if (Improbable.check(player, 5.0f, now)) cancel = true; - // Reset, to prevent endless violation level farming. - data.fastBreakDamageTime = now; - data.clickedX = block.getX(); - data.clickedY = block.getY(); - data.clickedZ = block.getZ(); } return cancel;