Improved performance for fluid spread handling.

This very spammy event has always been costly.  It still is, but this
change makes each instance a lot cheaper, with slightly reduced
functionality.
This commit is contained in:
ryanhamshire 2014-09-30 18:54:09 -07:00
parent b72d0e100f
commit 259e285847

View File

@ -638,6 +638,7 @@ public class BlockEventHandler implements Listener
//ensures fluids don't flow out of claims, unless into another claim where the owner is trusted to build //ensures fluids don't flow out of claims, unless into another claim where the owner is trusted to build
private Claim lastSpreadClaim = null; private Claim lastSpreadClaim = null;
private Location lastSpreadSourceLocation = null;
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onBlockFromTo (BlockFromToEvent spreadEvent) public void onBlockFromTo (BlockFromToEvent spreadEvent)
{ {
@ -649,41 +650,40 @@ public class BlockEventHandler implements Listener
//from where? //from where?
Block fromBlock = spreadEvent.getBlock(); Block fromBlock = spreadEvent.getBlock();
Claim fromClaim = this.dataStore.getClaimAt(fromBlock.getLocation(), false, this.lastSpreadClaim); Claim fromClaim = null;
if(fromClaim != null) if(fromBlock.getLocation().equals(lastSpreadSourceLocation))
{ {
this.lastSpreadClaim = fromClaim; fromClaim = lastSpreadClaim;
}
else
{
fromClaim = this.dataStore.getClaimAt(fromBlock.getLocation(), false, this.lastSpreadClaim);
lastSpreadClaim = fromClaim;
lastSpreadSourceLocation = fromBlock.getLocation();
} }
//where to? //where to?
Block toBlock = spreadEvent.getToBlock(); Block toBlock = spreadEvent.getToBlock();
Claim toClaim = this.dataStore.getClaimAt(toBlock.getLocation(), false, fromClaim);
//if it's within the same claim or wilderness to wilderness, allow it //if from a land claim, this is easy and cheap - just don't allow for flowing out of that claim
if(fromClaim == toClaim) return; if(fromClaim != null)
//block any spread into the wilderness from a claim
if(fromClaim != null && toClaim == null)
{ {
spreadEvent.setCancelled(true); if(!fromClaim.contains(toBlock.getLocation(), false, false))
return; {
spreadEvent.setCancelled(true);
}
} }
//if spreading into a claim //otherwise, just prevent spreading into a claim from outside
else if(toClaim != null) else
{ {
//who owns the spreading block, if anyone? Claim toClaim = this.dataStore.getClaimAt(toBlock.getLocation(), false, fromClaim);
OfflinePlayer fromOwner = null;
if(fromClaim != null) //if spreading into a claim
{ if(toClaim != null)
fromOwner = GriefPrevention.instance.getServer().getOfflinePlayer(fromClaim.ownerID); {
} spreadEvent.setCancelled(true);
}
//cancel unless the owner of the spreading block is allowed to build in the receiving claim
if(fromOwner == null || fromOwner.getPlayer() == null || toClaim.allowBuild(fromOwner.getPlayer()) != null)
{
spreadEvent.setCancelled(true);
}
} }
} }