Add new method for fastbreak (switchable).

This commit is contained in:
asofold 2012-09-10 20:54:19 +02:00
parent 544e0a06be
commit 256fd6b26f
6 changed files with 93 additions and 36 deletions

View File

@ -75,11 +75,15 @@ public class BlockBreakConfig extends ACheckConfig {
public final ActionList directionActions;
public final boolean fastBreakCheck;
public final int fastBreakBuckets;
public final long fastBreakBucketDur;
public final int fastBreakBuffer;
public final long fastBreakContention;
public final int fastBreakInterval;
public final boolean fastBreakOldCheck;
public final ActionList fastBreakActions;
public boolean improbableFastBreakCheck;
public boolean improbableFastBreakCheck;
public final boolean noSwingCheck;
public final ActionList noSwingActions;
@ -87,10 +91,9 @@ public class BlockBreakConfig extends ACheckConfig {
public final boolean reachCheck;
public final ActionList reachActions;
public final boolean wrongBlockCheck;
public final ActionList wrongBlockActions;
/**
* Instantiates a new block break configuration.
*
@ -102,8 +105,12 @@ public class BlockBreakConfig extends ACheckConfig {
directionActions = data.getActionList(ConfPaths.BLOCKBREAK_DIRECTION_ACTIONS, Permissions.BLOCKBREAK_DIRECTION);
fastBreakCheck = data.getBoolean(ConfPaths.BLOCKBREAK_FASTBREAK_CHECK);
fastBreakContention = data.getLong(ConfPaths.BLOCKBREAK_FASTBREAK_BUCKETS_CONTENTION, 2000);
fastBreakBucketDur = data.getInt(ConfPaths.BLOCKBREAK_FASTBREAK_BUCKETS_DUR, 1000);
fastBreakBuckets = data.getInt(ConfPaths.BLOCKBREAK_FASTBREAK_BUCKETS_N, 30);
fastBreakBuffer = data.getInt(ConfPaths.BLOCKBREAK_FASTBREAK_BUFFER);
fastBreakInterval = data.getInt(ConfPaths.BLOCKBREAK_FASTBREAK_INTERVAL);
fastBreakOldCheck = data.getBoolean(ConfPaths.BLOCKBREAK_FASTBREAK_OLDCHECK);
fastBreakActions = data.getActionList(ConfPaths.BLOCKBREAK_FASTBREAK_ACTIONS, Permissions.BLOCKBREAK_FASTBREAK);
improbableFastBreakCheck = data.getBoolean(ConfPaths.COMBINED_IMPROBABLE_FASTBREAK_CHECK);

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.checks.ACheckData;
import fr.neatmonster.nocheatplus.checks.ICheckData;
import fr.neatmonster.nocheatplus.checks.CheckDataFactory;
import fr.neatmonster.nocheatplus.utilities.ActionFrequency;
/*
* M#"""""""'M dP dP M#"""""""'M dP
@ -47,7 +48,7 @@ public class BlockBreakData extends ACheckData {
/** The map containing the data per players. */
private static final Map<String, BlockBreakData> playersMap = new HashMap<String, BlockBreakData>();
/**
/**
* Gets the data of a specified player.
*
* @param player
@ -56,7 +57,7 @@ public class BlockBreakData extends ACheckData {
*/
public static BlockBreakData getData(final Player player) {
if (!playersMap.containsKey(player.getName()))
playersMap.put(player.getName(), new BlockBreakData());
playersMap.put(player.getName(), new BlockBreakData(BlockBreakConfig.getConfig(player)));
return playersMap.get(player.getName());
}
@ -77,8 +78,10 @@ public class BlockBreakData extends ACheckData {
public int clickedZ;
// Data of the fast break check.
public int fastBreakBuffer = 5;
public final ActionFrequency fastBreakPenalties;
public int fastBreakBuffer;
public long fastBreakBreakTime = System.currentTimeMillis() - 1000L;
/** Old check sets this to the last interact time, new check sets to first interact time */
public long fastBreakDamageTime = System.currentTimeMillis();
// Data of the no swing check.
@ -86,5 +89,11 @@ public class BlockBreakData extends ACheckData {
// Data of the reach check.
public double reachDistance;
public BlockBreakData(BlockBreakConfig cc) {
fastBreakBuffer = cc.fastBreakBuffer;
fastBreakPenalties = new ActionFrequency(cc.fastBreakBuckets, cc.fastBreakBucketDur);
}
}

View File

@ -5,6 +5,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerInteractEvent;
@ -137,18 +138,21 @@ public class BlockBreakListener implements Listener {
* |_| |_|\__,_|\__, |\___|_| |___|_| |_|\__\___|_| \__,_|\___|\__|
* |___/
*/
final Player player = event.getPlayer();
final BlockBreakConfig cc = BlockBreakConfig.getConfig(player);
// Return if it is not left clicking a block.
if (!cc.fastBreakOldCheck && event.getAction() != Action.LEFT_CLICK_BLOCK) return;
// Do not care about null blocks.
final Block block = event.getClickedBlock();
if (block == null)
return;
final BlockBreakData data = BlockBreakData.getData(event.getPlayer());
final BlockBreakData data = BlockBreakData.getData(player);
if (!cc.fastBreakOldCheck && data.clickedX == block.getX() && data.clickedZ == block.getZ() && data.clickedY == block.getY()) return;
// Only record first damage:
data.fastBreakDamageTime = System.currentTimeMillis();
// Also set last clicked blocks position.
// ? only set time / block, if
// - action = left_click_block
// - time not already set => design to really record the used time.
// DRAWBACK: lag, thus: rather switch to accumulate the theoretically needed break times in an ActionFrequency buffer,
// then use those to determine if to prevent or not, depending on settings + lag.
data.clickedX = block.getX();
data.clickedY = block.getY();
data.clickedZ = block.getZ();

View File

@ -47,6 +47,7 @@ public class FastBreak extends Check {
* @return true, if successful
*/
public boolean check(final Player player, final Block block) {
final long now = System.currentTimeMillis();
final BlockBreakConfig cc = BlockBreakConfig.getConfig(player);
final BlockBreakData data = BlockBreakData.getData(player);
@ -56,38 +57,68 @@ public class FastBreak extends Check {
long elapsedTimeLimit = Math.round(cc.fastBreakInterval / 100D * SURVIVAL);
if (player.getGameMode() == GameMode.CREATIVE)
elapsedTimeLimit = Math.round(cc.fastBreakInterval / 100D * CREATIVE);
// TODO: Use exact time for block types with new method !
if (cc.fastBreakOldCheck){
// The elapsed time is the difference between the last damage time and the last break time.
final long elapsedTime = data.fastBreakDamageTime - data.fastBreakBreakTime;
if (elapsedTime < elapsedTimeLimit && data.fastBreakBreakTime > 0L && data.fastBreakDamageTime > 0L
&& (player.getItemInHand().getType() != Material.SHEARS || block.getType() != Material.LEAVES)) {
// If the buffer has been consumed.
if (data.fastBreakBuffer <= 0) {
// Increment the violation level (but using the original limit).
data.fastBreakVL += elapsedTimeLimit - elapsedTime;
// The elapsed time is the difference between the last damage time and the last break time.
final long elapsedTime = data.fastBreakDamageTime - data.fastBreakBreakTime;
if (elapsedTime < elapsedTimeLimit && data.fastBreakBreakTime > 0L && data.fastBreakDamageTime > 0L
&& (player.getItemInHand().getType() != Material.SHEARS || block.getType() != Material.LEAVES)) {
// If the buffer has been consumed.
if (data.fastBreakBuffer <= 0) {
// Increment the violation level (but using the original limit).
data.fastBreakVL += elapsedTimeLimit - elapsedTime;
// Cancel the event if needed.
cancel = executeActions(player, data.fastBreakVL, elapsedTimeLimit - elapsedTime, cc.fastBreakActions);
} else
// Remove one from the buffer.
data.fastBreakBuffer--;
} else {
// If the buffer isn't full.
if (data.fastBreakBuffer < cc.fastBreakBuffer)
// Add one to the buffer.
data.fastBreakBuffer++;
// Cancel the event if needed.
cancel = executeActions(player, data.fastBreakVL, elapsedTimeLimit - elapsedTime, cc.fastBreakActions);
} else
// Remove one from the buffer.
data.fastBreakBuffer--;
} else {
// If the buffer isn't full.
if (data.fastBreakBuffer < cc.fastBreakBuffer)
// Add one to the buffer.
data.fastBreakBuffer++;
// Reduce the violation level, the player was nice with blocks.
data.fastBreakVL *= 0.9D;
// Reduce the violation level, the player was nice with blocks.
data.fastBreakVL *= 0.9D;
}
}
else{
// fastBreakDamageTime is now first interact on block (!).
if (now - data.fastBreakDamageTime < elapsedTimeLimit){
// lag or cheat or Minecraft.
final long elapsedTime = now - data.fastBreakDamageTime;
final long missingTime = elapsedTimeLimit - elapsedTime;
// Add as penalty
data.fastBreakPenalties.add(now, (float) missingTime);
if (data.fastBreakPenalties.getScore(1f) > cc.fastBreakContention){
data.fastBreakVL += missingTime;
cancel = executeActions(player, data.fastBreakVL, missingTime, cc.fastBreakActions);
}
// else: still within contention limits.
// System.out.println("violation : " + missingTime);
}
else{
data.fastBreakVL *= 0.9D;
}
}
// Remember the block breaking time.
data.fastBreakBreakTime = System.currentTimeMillis();
data.fastBreakBreakTime = now;
// Combined speed:
// TODO: use some value corresponding to allowed block breaking speed !
if (cc.improbableFastBreakCheck && Improbable.check(player, 1f, System.currentTimeMillis()))
if (cc.improbableFastBreakCheck && Improbable.check(player, 1f, now))
cancel = true;
return cancel;

View File

@ -67,8 +67,13 @@ public abstract class ConfPaths {
private static final String BLOCKBREAK_FASTBREAK = BLOCKBREAK + "fastbreak.";
public static final String BLOCKBREAK_FASTBREAK_CHECK = BLOCKBREAK_FASTBREAK + "active";
private static final String BLOCKBREAK_FASTBREAK_BUCKETS = BLOCKBREAK + "buckets.";
public static final String BLOCKBREAK_FASTBREAK_BUCKETS_CONTENTION = BLOCKBREAK_FASTBREAK_BUCKETS + "contention";
public static final String BLOCKBREAK_FASTBREAK_BUCKETS_N = BLOCKBREAK_FASTBREAK_BUCKETS + "number";
public static final String BLOCKBREAK_FASTBREAK_BUCKETS_DUR = BLOCKBREAK_FASTBREAK_BUCKETS + "duration";
public static final String BLOCKBREAK_FASTBREAK_BUFFER = BLOCKBREAK_FASTBREAK + "buffer";
public static final String BLOCKBREAK_FASTBREAK_INTERVAL = BLOCKBREAK_FASTBREAK + "interval";
public static final String BLOCKBREAK_FASTBREAK_OLDCHECK = BLOCKBREAK_FASTBREAK + "oldcheck";
public static final String BLOCKBREAK_FASTBREAK_ACTIONS = BLOCKBREAK_FASTBREAK + "actions";
private static final String BLOCKBREAK_NOSWING = BLOCKBREAK + "noswing.";

View File

@ -71,6 +71,7 @@ public class DefaultConfig extends ConfigFile {
set(ConfPaths.BLOCKBREAK_FASTBREAK_CHECK, true);
set(ConfPaths.BLOCKBREAK_FASTBREAK_BUFFER, 2);
set(ConfPaths.BLOCKBREAK_FASTBREAK_INTERVAL, 100);
set(ConfPaths.BLOCKBREAK_FASTBREAK_OLDCHECK, false);
set(ConfPaths.BLOCKBREAK_FASTBREAK_ACTIONS, "cancel vl>100 log:fastbreak:3:5:cif cancel");
set(ConfPaths.BLOCKBREAK_NOSWING_CHECK, true);