Ensure wrongBlock does not add Integer.MAX_VALUE as violation level.

Also cap violation at 4.
This commit is contained in:
asofold 2014-03-01 15:13:58 +01:00
parent 894aa466d6
commit ce5a90201c

View File

@ -31,7 +31,7 @@ public class WrongBlock extends Check {
boolean cancel = false;
final boolean wrongTime = data.fastBreakfirstDamage < data.fastBreakBreakTime;
final int dist = TrigUtil.manhattan(data.clickedX, data.clickedY, data.clickedZ, block);
final int dist = Math.min(4, data.clickedX == Integer.MAX_VALUE ? 100 : TrigUtil.manhattan(data.clickedX, data.clickedY, data.clickedZ, block));
final boolean wrongBlock;
final long now = System.currentTimeMillis();
if (dist == 0) {
@ -44,29 +44,33 @@ public class WrongBlock extends Check {
}
else if (dist == 1) {
// One might to a concession in case of instant breaking.
if (now - data.wasInstaBreak < 60)
if (now - data.wasInstaBreak < 60) {
wrongBlock = false;
else
}
else {
wrongBlock = true;
}
else
}
else {
// Note that the maximally counted distance is set above.
wrongBlock = true;
}
if (wrongBlock) {
// Manhattan distance.
if ((cc.fastBreakDebug || cc.debug) && player.hasPermission(Permissions.ADMINISTRATION_DEBUG)) {
player.sendMessage("WrongBlock failure with dist: " + dist);
}
data.wrongBlockVL.add(now, (float) (dist + 1) / 2f);
final float score = data.wrongBlockVL.score(0.9f);
if (score > cc.wrongBLockLevel) {
if (executeActions(player, score, 1D, cc.wrongBlockActions))
if (executeActions(player, score, 1D, cc.wrongBlockActions)) {
cancel = true;
if (Improbable.check(player, 2.0f, now, "blockbreak.wrongblock"))
}
if (Improbable.check(player, 2.0f, now, "blockbreak.wrongblock")) {
cancel = true;
}
}
}
return cancel;
}