From 5bfad6016c9bd78bcd1c675618a7d91c4fcd7e53 Mon Sep 17 00:00:00 2001 From: asofold Date: Fri, 13 Jun 2014 10:58:41 +0200 Subject: [PATCH] Small cleanup for fastbreak: creative mode is not handled by this check. --- .../checks/blockbreak/BlockBreakConfig.java | 2 - .../checks/blockbreak/BlockBreakListener.java | 14 +++--- .../checks/blockbreak/FastBreak.java | 49 +++++++++---------- .../nocheatplus/config/ConfPaths.java | 3 +- 4 files changed, 33 insertions(+), 35 deletions(-) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakConfig.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakConfig.java index ddcdaef0..5196d375 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakConfig.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakConfig.java @@ -65,7 +65,6 @@ public class BlockBreakConfig extends ACheckConfig { public final long fastBreakGrace; public final long fastBreakDelay; public final int fastBreakModSurvival; - public final int fastBreakModCreative; public final ActionList fastBreakActions; @@ -112,7 +111,6 @@ public class BlockBreakConfig extends ACheckConfig { fastBreakBucketDur = data.getInt(ConfPaths.BLOCKBREAK_FASTBREAK_BUCKETS_DUR, 4000); fastBreakBucketFactor = (float) data.getDouble(ConfPaths.BLOCKBREAK_FASTBREAK_BUCKETS_FACTOR, 0.99); fastBreakBuckets = data.getInt(ConfPaths.BLOCKBREAK_FASTBREAK_BUCKETS_N, 30); - fastBreakModCreative = data.getInt(ConfPaths.BLOCKBREAK_FASTBREAK_MOD_CREATIVE, 0); fastBreakModSurvival = data.getInt(ConfPaths.BLOCKBREAK_FASTBREAK_MOD_SURVIVAL); // Fastbreak actions, shared. fastBreakActions = data.getOptimizedActionList(ConfPaths.BLOCKBREAK_FASTBREAK_ACTIONS, Permissions.BLOCKBREAK_FASTBREAK); diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakListener.java index 451f8b6b..019dde9d 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakListener.java @@ -61,8 +61,7 @@ public class BlockBreakListener extends CheckListener { * @param event * the event */ - @EventHandler( - ignoreCancelled = false, priority = EventPriority.LOWEST) + @EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST) public void onBlockBreak(final BlockBreakEvent event) { final Player player = event.getPlayer(); @@ -227,8 +226,9 @@ public class BlockBreakListener extends CheckListener { // } // Do not care about null blocks. - if (block == null) - return; + if (block == null) { + return; + } final int tick = TickTask.getTick(); // Skip if already set to the same block without breaking within one tick difference. @@ -236,9 +236,11 @@ public class BlockBreakListener extends CheckListener { final Material tool = stack == null ? null: stack.getType(); if (data.toolChanged(tool)) { // Update. - } else if (tick < data.clickedTick) { - // Update. + } else if (tick < data.clickedTick || now < data.fastBreakfirstDamage || now < data.fastBreakBreakTime) { + // Time/tick ran backwards: Update. + // Tick running backwards should not happen in the main thread unless for reload. A plugin could reset it (not intended). } else if (data.fastBreakBreakTime < data.fastBreakfirstDamage && data.clickedX == block.getX() && data.clickedZ == block.getZ() && data.clickedY == block.getY()){ + // Preserve first damage time. if (tick - data.clickedTick <= 1 ) { return; } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockbreak/FastBreak.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockbreak/FastBreak.java index 364feef7..6d4d52c5 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockbreak/FastBreak.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockbreak/FastBreak.java @@ -1,6 +1,5 @@ package fr.neatmonster.nocheatplus.checks.blockbreak; -import org.bukkit.GameMode; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -29,7 +28,7 @@ public class FastBreak extends Check { } /** - * Checks a player. + * Checks a player for fastbreak. This is NOT for creative mode. * * @param player * the player @@ -45,70 +44,68 @@ public class FastBreak extends Check { final long now = System.currentTimeMillis(); boolean cancel = false; - // First, check the game mode of the player and choose the right limit. - final long breakingTime; + // Determine expected breaking time by block type. final int id = block.getTypeId(); - if (player.getGameMode() == GameMode.CREATIVE) - // Modifier defaults to 0, the Frequency check is responsible for those. - breakingTime = Math.max(0, Math.round((double) cc.fastBreakModCreative / 100D * (double) 100)); - else - breakingTime = Math.max(0, Math.round((double) cc.fastBreakModSurvival / 100D * (double) BlockProperties.getBreakingDuration(id, player))); - // fastBreakfirstDamage is the first interact on block (!). + final long expectedBreakingTime = Math.max(0, Math.round((double) BlockProperties.getBreakingDuration(id, player) * (double) cc.fastBreakModSurvival / 100D)); + final long elapsedTime; + // TODO: Concept for unbreakable blocks? Context: extreme VL. // TODO: Should it be breakingTime instead of 0 for inconsistencies? - if (cc.fastBreakStrict){ + if (cc.fastBreakStrict) { // Counting interact...break. elapsedTime = (data.fastBreakBreakTime > data.fastBreakfirstDamage) ? 0 : now - data.fastBreakfirstDamage; } - else{ + else { // Counting break...break. elapsedTime = (data.fastBreakBreakTime > now) ? 0 : now - data.fastBreakBreakTime; } // Check if the time used time is lower than expected. - if (isInstaBreak.decideOptimistically()){ + if (isInstaBreak.decideOptimistically()) { // Ignore those for now. // TODO: Find out why this was commented out long ago a) did not fix mcMMO b) exploits. // TODO: Maybe adjust time to min(time, SOMETHING) for MAYBE/YES. } - else if (elapsedTime < 0){ + else if (elapsedTime < 0) { // Ignore it. TODO: ? } - else if (elapsedTime + cc.fastBreakDelay < breakingTime){ + else if (elapsedTime + cc.fastBreakDelay < expectedBreakingTime) { // lag or cheat or Minecraft. // Count in server side lag, if desired. - final float lag = cc.lag ? TickTask.getLag(breakingTime, true) : 1f; + final float lag = cc.lag ? TickTask.getLag(expectedBreakingTime, true) : 1f; - final long missingTime = breakingTime - (long) (lag * elapsedTime); + final long missingTime = expectedBreakingTime - (long) (lag * elapsedTime); - if (missingTime > 0){ + if (missingTime > 0) { // Add as penalty data.fastBreakPenalties.add(now, (float) missingTime); // Only raise a violation, if the total penalty score exceeds the contention duration (for lag, delay). - if (data.fastBreakPenalties.score(cc.fastBreakBucketFactor) > cc.fastBreakGrace){ + if (data.fastBreakPenalties.score(cc.fastBreakBucketFactor) > cc.fastBreakGrace) { // TODO: maybe add one absolute penalty time for big amounts to stop breaking until then final double vlAdded = (double) missingTime / 1000.0; data.fastBreakVL += vlAdded; final ViolationData vd = new ViolationData(this, player, data.fastBreakVL, vlAdded, cc.fastBreakActions); - if (vd.needsParameters()) vd.setParameter(ParameterName.BLOCK_ID, "" + id); + if (vd.needsParameters()) { + vd.setParameter(ParameterName.BLOCK_ID, "" + id); + } cancel = executeActions(vd); } // else: still within contention limits. } } - else if (breakingTime > cc.fastBreakDelay){ + else if (expectedBreakingTime > cc.fastBreakDelay) { // Fast breaking does not decrease violation level. data.fastBreakVL *= 0.9D; } - if ((cc.fastBreakDebug || cc.debug) && player.hasPermission(Permissions.ADMINISTRATION_DEBUG)){ + if ((cc.fastBreakDebug || cc.debug) && player.hasPermission(Permissions.ADMINISTRATION_DEBUG)) { // General stats: - if (data.stats != null){ + if (data.stats != null) { data.stats.addStats(data.stats.getId(Integer.toString(block.getTypeId())+"u", true), elapsedTime); - data.stats.addStats(data.stats.getId(Integer.toString(block.getTypeId())+ "r", true), breakingTime); + data.stats.addStats(data.stats.getId(Integer.toString(block.getTypeId())+ "r", true), expectedBreakingTime); player.sendMessage(data.stats.getStatsStr(true)); } // Send info about current break: @@ -116,10 +113,10 @@ public class FastBreak extends Check { final ItemStack stack = player.getItemInHand(); final boolean isValidTool = BlockProperties.isValidTool(blockId, stack); final double haste = PotionUtil.getPotionEffectAmplifier(player, PotionEffectType.FAST_DIGGING); - String msg = (isInstaBreak.decideOptimistically() ? ("[Insta=" + isInstaBreak + "]") : "[Normal]") + "[" + blockId + "] "+ elapsedTime + "u / " + breakingTime +"r (" + (isValidTool?"tool":"no-tool") + ")" + (haste == Double.NEGATIVE_INFINITY ? "" : " haste=" + ((int) haste + 1)); + String msg = (isInstaBreak.decideOptimistically() ? ("[Insta=" + isInstaBreak + "]") : "[Normal]") + "[" + blockId + "] "+ elapsedTime + "u / " + expectedBreakingTime +"r (" + (isValidTool?"tool":"no-tool") + ")" + (haste == Double.NEGATIVE_INFINITY ? "" : " haste=" + ((int) haste + 1)); player.sendMessage(msg); // net.minecraft.server.Item mcItem = net.minecraft.server.Item.byId[stack.getTypeId()]; -// if (mcItem != null){ +// if (mcItem != null) { // double x = mcItem.getDestroySpeed(((CraftItemStack) stack).getHandle(), net.minecraft.server.Block.byId[blockId]); // player.sendMessage("mc speed: " + x); // } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java index 5abfaf80..58440013 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -124,7 +124,6 @@ public abstract class ConfPaths { public static final String BLOCKBREAK_FASTBREAK_BUCKETS_FACTOR = BLOCKBREAK_FASTBREAK_BUCKETS + "factor"; public static final String BLOCKBREAK_FASTBREAK_DELAY = BLOCKBREAK_FASTBREAK + "delay"; public static final String BLOCKBREAK_FASTBREAK_GRACE = BLOCKBREAK_FASTBREAK + "grace"; - public static final String BLOCKBREAK_FASTBREAK_MOD_CREATIVE = BLOCKBREAK_FASTBREAK + "intervalcreative"; public static final String BLOCKBREAK_FASTBREAK_MOD_SURVIVAL = BLOCKBREAK_FASTBREAK + "intervalsurvival"; public static final String BLOCKBREAK_FASTBREAK_ACTIONS = BLOCKBREAK_FASTBREAK + "actions"; @@ -617,5 +616,7 @@ public abstract class ConfPaths { public static final String INVENTORY_ENSURECLOSE = "checks.inventory.ensureclose"; @Deprecated public static final String MISCELLANEOUS_REPORTTOMETRICS = "miscellaneous.reporttometrics"; + @Deprecated + public static final String BLOCKBREAK_FASTBREAK_MOD_CREATIVE = "checks.blockbreak.fastbreak.intervalcreative"; }