Don't update physics when block place is cancelled. Fixes BUKKIT-3939

When a block placement happens we currently update physics on the
attempted placement and update again if the placement is cancelled.
To correct the first one we simply set the block without applying
physics. To correct the second we have to add a new method to
BlockState that lets us update without applying physics and use
this method method when putting the block back.
This commit is contained in:
Travis Watkins 2013-03-31 19:18:42 -05:00
parent d3dbb1bb50
commit 71a475f076
12 changed files with 29 additions and 25 deletions

View file

@ -80,11 +80,11 @@ public class ItemBlock extends Item {
org.bukkit.block.BlockState blockstate = org.bukkit.craftbukkit.block.CraftBlockState.getBlockState(world, x, y, z);
world.callingPlaceEvent = true;
world.setTypeIdAndData(x, y, z, id, data, 3);
world.setTypeIdAndData(x, y, z, id, data, 2);
org.bukkit.event.block.BlockPlaceEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockstate, clickedX, clickedY, clickedZ);
if (event.isCancelled() || !event.canBuild()) {
blockstate.update(true);
blockstate.update(true, false);
world.callingPlaceEvent = false;
return false;
}

View file

@ -24,8 +24,8 @@ public class CraftBeacon extends CraftBlockState implements Beacon {
}
@Override
public boolean update(boolean force) {
boolean result = super.update(force);
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result) {
beacon.update();

View file

@ -113,17 +113,21 @@ public class CraftBlockState implements BlockState {
}
public boolean update(boolean force) {
return update(force, true);
}
public boolean update(boolean force, boolean applyPhysics) {
Block block = getBlock();
if (block.getType() != this.getType()) {
if (block.getType() != getType()) {
if (force) {
block.setTypeId(this.getTypeId());
block.setTypeId(getTypeId(), applyPhysics);
} else {
return false;
}
}
block.setData(getRawData());
block.setData(getRawData(), applyPhysics);
world.getHandle().notify(x, y, z);
return true;

View file

@ -21,8 +21,8 @@ public class CraftBrewingStand extends CraftBlockState implements BrewingStand {
}
@Override
public boolean update(boolean force) {
boolean result = super.update(force);
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result) {
brewingStand.update();

View file

@ -61,8 +61,8 @@ public class CraftChest extends CraftBlockState implements Chest {
}
@Override
public boolean update(boolean force) {
boolean result = super.update(force);
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result) {
chest.update();

View file

@ -35,8 +35,8 @@ public class CraftCommandBlock extends CraftBlockState implements CommandBlock {
this.name = name != null ? name : "@";
}
public boolean update(boolean forced) {
boolean result = super.update(forced);
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result) {
commandBlock.b(command);

View file

@ -39,8 +39,8 @@ public class CraftDispenser extends CraftBlockState implements Dispenser {
}
@Override
public boolean update(boolean force) {
boolean result = super.update(force);
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result) {
dispenser.update();

View file

@ -36,8 +36,8 @@ public class CraftDropper extends CraftBlockState implements Dropper {
}
@Override
public boolean update(boolean force) {
boolean result = super.update(force);
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result) {
dropper.update();

View file

@ -21,8 +21,8 @@ public class CraftFurnace extends CraftBlockState implements Furnace {
}
@Override
public boolean update(boolean force) {
boolean result = super.update(force);
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result) {
furnace.update();

View file

@ -21,8 +21,8 @@ public class CraftHopper extends CraftBlockState implements Hopper {
}
@Override
public boolean update(boolean force) {
boolean result = super.update(force);
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result) {
hopper.update();

View file

@ -31,8 +31,8 @@ public class CraftSign extends CraftBlockState implements Sign {
}
@Override
public boolean update(boolean force) {
boolean result = super.update(force);
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result) {
for(int i = 0; i < 4; i++) {

View file

@ -181,8 +181,8 @@ public class CraftSkull extends CraftBlockState implements Skull {
}
@Override
public boolean update(boolean force) {
boolean result = super.update(force);
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result) {
skull.setSkullType(getSkullType(skullType), player);