Navigation Menu

Skip to content

Commit

Permalink
Reduce the number of BlockFromTo events handled.
Browse files Browse the repository at this point in the history
  • Loading branch information
sk89q committed Aug 18, 2014
1 parent 929f9e9 commit 039d174
Showing 1 changed file with 14 additions and 3 deletions.
Expand Up @@ -356,17 +356,28 @@ public void onPlayerBucketFill(PlayerBucketFillEvent event) {
public void onBlockFromTo(BlockFromToEvent event) {
Block from = event.getBlock();
Block to = event.getToBlock();
Material fromType = from.getType();
Material toType = to.getType();

// Liquids pass this event when flowing to solid blocks
if (to.getType().isSolid() && Materials.isLiquid(from.getType())) {
if (toType.isSolid() && Materials.isLiquid(fromType)) {
return;
}

// This significantly reduces the number of events without having
// too much effect. Unfortunately it appears that even if this
// check didn't exist, you can raise the level of some liquid
// flow and the from/to data may not be correct.
if ((Materials.isWater(fromType) && Materials.isWater(toType)) || (Materials.isLava(fromType) && Materials.isLava(toType))) {
return;
}

Cause cause = create(from);

if (from.getType() != Material.AIR) {
// Disable since it's probably not needed
/*if (from.getType() != Material.AIR) {
Events.fireToCancel(event, new BreakBlockEvent(event, cause, to));
}
}*/

Events.fireToCancel(event, new PlaceBlockEvent(event, cause, to.getLocation(), from.getType()));
}
Expand Down

0 comments on commit 039d174

Please sign in to comment.