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

@ -26,45 +26,49 @@ public class WrongBlock extends Check {
* @param isInstaBreak
* @return
*/
public boolean check(final Player player, final Block block, final BlockBreakConfig cc, final BlockBreakData data, final boolean isInstaBreak){
public boolean check(final Player player, final Block block, final BlockBreakConfig cc, final BlockBreakData data, final boolean isInstaBreak) {
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){
if (wrongTime){
if (dist == 0) {
if (wrongTime) {
data.fastBreakBreakTime = now;
data.fastBreakfirstDamage = now;
// Could set to wrong block, but prefer to transform it into a quasi insta break.
}
wrongBlock = false;
}
else if (dist == 1){
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)){
if (wrongBlock) {
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 (score > cc.wrongBLockLevel) {
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;
}
}
}