Fix issue with replacing broken blocks.

This commit is contained in:
asofold 2012-09-12 20:28:36 +02:00
parent c1195c630a
commit 19ca256c30
7 changed files with 33 additions and 29 deletions

View File

@ -76,33 +76,47 @@ public class BlockBreakListener implements Listener {
// Do the actual checks, if still needed. It's a good idea to make computationally cheap checks first, because
// it may save us from doing the computationally expensive checks.
final BlockBreakConfig cc = BlockBreakConfig.getConfig(player);
final BlockBreakData data = BlockBreakData.getData(player);
final long now = System.currentTimeMillis();
// Has the player broken a block that was not damaged before?
if (wrongBlock.isEnabled(player) && wrongBlock.check(player, block))
if (wrongBlock.isEnabled(player) && wrongBlock.check(player, block, cc, data))
cancelled = true;
// Has the player broken more blocks per second than allowed?
if (!cancelled && frequency.isEnabled(player) && frequency.check(player))
if (!cancelled && frequency.isEnabled(player) && frequency.check(player, cc, data))
cancelled = true;
// Has the player broken blocks faster than possible?
if (!cancelled && fastBreak.isEnabled(player) && fastBreak.check(player, block))
if (!cancelled && fastBreak.isEnabled(player) && fastBreak.check(player, block, cc, data))
cancelled = true;
// Did the arm of the player move before breaking this block?
if (!cancelled && noSwing.isEnabled(player) && noSwing.check(player))
if (!cancelled && noSwing.isEnabled(player) && noSwing.check(player, data))
cancelled = true;
// Is the block really in reach distance?
if (!cancelled && reach.isEnabled(player) && reach.check(player, block.getLocation()))
if (!cancelled && reach.isEnabled(player) && reach.check(player, block.getLocation(), data))
cancelled = true;
// Did the player look at the block at all?
if (!cancelled && direction.isEnabled(player) && direction.check(player, block.getLocation()))
if (!cancelled && direction.isEnabled(player) && direction.check(player, block.getLocation(), data))
cancelled = true;
// At least one check failed and demanded to cancel the event.
if (cancelled)
if (cancelled){
event.setCancelled(cancelled);
// Reset damage position:
data.fastBreakDamageTime = now;
data.clickedX = block.getX();
data.clickedY = block.getY();
data.clickedZ = block.getZ();
}
else{
// Invalidate last damage position:
data.clickedX = Integer.MAX_VALUE;
}
}

View File

@ -38,8 +38,7 @@ public class Direction extends Check {
* the location
* @return true, if successful
*/
public boolean check(final Player player, final Location location) {
final BlockBreakData data = BlockBreakData.getData(player);
public boolean check(final Player player, final Location location, final BlockBreakData data) {
boolean cancel = false;

View File

@ -38,13 +38,13 @@ public class FastBreak extends Check {
* the player
* @param block
* the block
* @param data
* @param cc
* @param elaspedTime
* @return true, if successful
*/
public boolean check(final Player player, final Block block) {
public boolean check(final Player player, final Block block, final BlockBreakConfig cc, final BlockBreakData data) {
final long now = System.currentTimeMillis();
final BlockBreakConfig cc = BlockBreakConfig.getConfig(player);
final BlockBreakData data = BlockBreakData.getData(player);
boolean cancel = false;

View File

@ -17,9 +17,7 @@ public class Frequency extends Check {
super(CheckType.BLOCKBREAK_FREQUENCY);
}
public boolean check(final Player player){
final BlockBreakConfig cc = BlockBreakConfig.getConfig(player);
final BlockBreakData data = BlockBreakData.getData(player);
public boolean check(final Player player, final BlockBreakConfig cc, final BlockBreakData data){
final float interval = (float) ((player.getGameMode() == GameMode.CREATIVE)?(cc.frequencyIntervalCreative):(cc.frequencyIntervalSurvival));
data.frequencyBuckets.add(System.currentTimeMillis(), interval);

View File

@ -34,8 +34,7 @@ public class NoSwing extends Check {
* the player
* @return true, if successful
*/
public boolean check(final Player player) {
final BlockBreakData data = BlockBreakData.getData(player);
public boolean check(final Player player, final BlockBreakData data) {
boolean cancel = false;

View File

@ -47,8 +47,7 @@ public class Reach extends Check {
* the location
* @return true, if successful
*/
public boolean check(final Player player, final Location location) {
final BlockBreakData data = BlockBreakData.getData(player);
public boolean check(final Player player, final Location location, final BlockBreakData data) {
boolean cancel = false;

View File

@ -19,11 +19,11 @@ public class WrongBlock extends Check {
* probably due to packet delaying issues for insta breaking. very effective against some nuker techniques.
* @param player
* @param block
* @param data
* @param cc
* @return
*/
public boolean check(final Player player, final Block block){
final BlockBreakConfig cc = BlockBreakConfig.getConfig(player);
final BlockBreakData data = BlockBreakData.getData(player);
public boolean check(final Player player, final Block block, final BlockBreakConfig cc, final BlockBreakData data){
boolean cancel = false;
if (data.clickedX != block.getX() || data.clickedZ != block.getZ() || data.clickedY != block.getY()){
@ -33,11 +33,6 @@ public class WrongBlock extends Check {
cancel = true;
if (Improbable.check(player, 5.0f, now))
cancel = true;
// Reset, to prevent endless violation level farming.
data.fastBreakDamageTime = now;
data.clickedX = block.getX();
data.clickedY = block.getY();
data.clickedZ = block.getZ();
}
return cancel;