Small cleanup for fastbreak: creative mode is not handled by this check.

This commit is contained in:
asofold 2014-06-13 10:58:41 +02:00
parent 587236dfdc
commit 5bfad6016c
4 changed files with 33 additions and 35 deletions

View File

@ -65,7 +65,6 @@ public class BlockBreakConfig extends ACheckConfig {
public final long fastBreakGrace; public final long fastBreakGrace;
public final long fastBreakDelay; public final long fastBreakDelay;
public final int fastBreakModSurvival; public final int fastBreakModSurvival;
public final int fastBreakModCreative;
public final ActionList fastBreakActions; public final ActionList fastBreakActions;
@ -112,7 +111,6 @@ public class BlockBreakConfig extends ACheckConfig {
fastBreakBucketDur = data.getInt(ConfPaths.BLOCKBREAK_FASTBREAK_BUCKETS_DUR, 4000); fastBreakBucketDur = data.getInt(ConfPaths.BLOCKBREAK_FASTBREAK_BUCKETS_DUR, 4000);
fastBreakBucketFactor = (float) data.getDouble(ConfPaths.BLOCKBREAK_FASTBREAK_BUCKETS_FACTOR, 0.99); fastBreakBucketFactor = (float) data.getDouble(ConfPaths.BLOCKBREAK_FASTBREAK_BUCKETS_FACTOR, 0.99);
fastBreakBuckets = data.getInt(ConfPaths.BLOCKBREAK_FASTBREAK_BUCKETS_N, 30); 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); fastBreakModSurvival = data.getInt(ConfPaths.BLOCKBREAK_FASTBREAK_MOD_SURVIVAL);
// Fastbreak actions, shared. // Fastbreak actions, shared.
fastBreakActions = data.getOptimizedActionList(ConfPaths.BLOCKBREAK_FASTBREAK_ACTIONS, Permissions.BLOCKBREAK_FASTBREAK); fastBreakActions = data.getOptimizedActionList(ConfPaths.BLOCKBREAK_FASTBREAK_ACTIONS, Permissions.BLOCKBREAK_FASTBREAK);

View File

@ -61,8 +61,7 @@ public class BlockBreakListener extends CheckListener {
* @param event * @param event
* the event * the event
*/ */
@EventHandler( @EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST)
ignoreCancelled = false, priority = EventPriority.LOWEST)
public void onBlockBreak(final BlockBreakEvent event) { public void onBlockBreak(final BlockBreakEvent event) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
@ -227,8 +226,9 @@ public class BlockBreakListener extends CheckListener {
// } // }
// Do not care about null blocks. // Do not care about null blocks.
if (block == null) if (block == null) {
return; return;
}
final int tick = TickTask.getTick(); final int tick = TickTask.getTick();
// Skip if already set to the same block without breaking within one tick difference. // 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(); final Material tool = stack == null ? null: stack.getType();
if (data.toolChanged(tool)) { if (data.toolChanged(tool)) {
// Update. // Update.
} else if (tick < data.clickedTick) { } else if (tick < data.clickedTick || now < data.fastBreakfirstDamage || now < data.fastBreakBreakTime) {
// Update. // 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()){ } 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 ) { if (tick - data.clickedTick <= 1 ) {
return; return;
} }

View File

@ -1,6 +1,5 @@
package fr.neatmonster.nocheatplus.checks.blockbreak; package fr.neatmonster.nocheatplus.checks.blockbreak;
import org.bukkit.GameMode;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; 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 * @param player
* the player * the player
@ -45,70 +44,68 @@ public class FastBreak extends Check {
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
boolean cancel = false; boolean cancel = false;
// First, check the game mode of the player and choose the right limit. // Determine expected breaking time by block type.
final long breakingTime;
final int id = block.getTypeId(); final int id = block.getTypeId();
if (player.getGameMode() == GameMode.CREATIVE) final long expectedBreakingTime = Math.max(0, Math.round((double) BlockProperties.getBreakingDuration(id, player) * (double) cc.fastBreakModSurvival / 100D));
// 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 elapsedTime; final long elapsedTime;
// TODO: Concept for unbreakable blocks? Context: extreme VL.
// TODO: Should it be breakingTime instead of 0 for inconsistencies? // TODO: Should it be breakingTime instead of 0 for inconsistencies?
if (cc.fastBreakStrict){ if (cc.fastBreakStrict) {
// Counting interact...break. // Counting interact...break.
elapsedTime = (data.fastBreakBreakTime > data.fastBreakfirstDamage) ? 0 : now - data.fastBreakfirstDamage; elapsedTime = (data.fastBreakBreakTime > data.fastBreakfirstDamage) ? 0 : now - data.fastBreakfirstDamage;
} }
else{ else {
// Counting break...break. // Counting break...break.
elapsedTime = (data.fastBreakBreakTime > now) ? 0 : now - data.fastBreakBreakTime; elapsedTime = (data.fastBreakBreakTime > now) ? 0 : now - data.fastBreakBreakTime;
} }
// Check if the time used time is lower than expected. // Check if the time used time is lower than expected.
if (isInstaBreak.decideOptimistically()){ if (isInstaBreak.decideOptimistically()) {
// Ignore those for now. // Ignore those for now.
// TODO: Find out why this was commented out long ago a) did not fix mcMMO b) exploits. // 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. // TODO: Maybe adjust time to min(time, SOMETHING) for MAYBE/YES.
} }
else if (elapsedTime < 0){ else if (elapsedTime < 0) {
// Ignore it. TODO: ? // Ignore it. TODO: ?
} }
else if (elapsedTime + cc.fastBreakDelay < breakingTime){ else if (elapsedTime + cc.fastBreakDelay < expectedBreakingTime) {
// lag or cheat or Minecraft. // lag or cheat or Minecraft.
// Count in server side lag, if desired. // 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 // Add as penalty
data.fastBreakPenalties.add(now, (float) missingTime); data.fastBreakPenalties.add(now, (float) missingTime);
// Only raise a violation, if the total penalty score exceeds the contention duration (for lag, delay). // 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 // TODO: maybe add one absolute penalty time for big amounts to stop breaking until then
final double vlAdded = (double) missingTime / 1000.0; final double vlAdded = (double) missingTime / 1000.0;
data.fastBreakVL += vlAdded; data.fastBreakVL += vlAdded;
final ViolationData vd = new ViolationData(this, player, data.fastBreakVL, vlAdded, cc.fastBreakActions); 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); cancel = executeActions(vd);
} }
// else: still within contention limits. // else: still within contention limits.
} }
} }
else if (breakingTime > cc.fastBreakDelay){ else if (expectedBreakingTime > cc.fastBreakDelay) {
// Fast breaking does not decrease violation level. // Fast breaking does not decrease violation level.
data.fastBreakVL *= 0.9D; 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: // 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())+"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)); player.sendMessage(data.stats.getStatsStr(true));
} }
// Send info about current break: // Send info about current break:
@ -116,10 +113,10 @@ public class FastBreak extends Check {
final ItemStack stack = player.getItemInHand(); final ItemStack stack = player.getItemInHand();
final boolean isValidTool = BlockProperties.isValidTool(blockId, stack); final boolean isValidTool = BlockProperties.isValidTool(blockId, stack);
final double haste = PotionUtil.getPotionEffectAmplifier(player, PotionEffectType.FAST_DIGGING); 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); player.sendMessage(msg);
// net.minecraft.server.Item mcItem = net.minecraft.server.Item.byId[stack.getTypeId()]; // 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]); // double x = mcItem.getDestroySpeed(((CraftItemStack) stack).getHandle(), net.minecraft.server.Block.byId[blockId]);
// player.sendMessage("mc speed: " + x); // player.sendMessage("mc speed: " + x);
// } // }

View File

@ -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_BUCKETS_FACTOR = BLOCKBREAK_FASTBREAK_BUCKETS + "factor";
public static final String BLOCKBREAK_FASTBREAK_DELAY = BLOCKBREAK_FASTBREAK + "delay"; 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_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_MOD_SURVIVAL = BLOCKBREAK_FASTBREAK + "intervalsurvival";
public static final String BLOCKBREAK_FASTBREAK_ACTIONS = BLOCKBREAK_FASTBREAK + "actions"; 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"; public static final String INVENTORY_ENSURECLOSE = "checks.inventory.ensureclose";
@Deprecated @Deprecated
public static final String MISCELLANEOUS_REPORTTOMETRICS = "miscellaneous.reporttometrics"; public static final String MISCELLANEOUS_REPORTTOMETRICS = "miscellaneous.reporttometrics";
@Deprecated
public static final String BLOCKBREAK_FASTBREAK_MOD_CREATIVE = "checks.blockbreak.fastbreak.intervalcreative";
} }