diff --git a/src/me/ryanhamshire/GriefPrevention/BlockEventHandler.java b/src/me/ryanhamshire/GriefPrevention/BlockEventHandler.java index 75926ac..87b37a4 100644 --- a/src/me/ryanhamshire/GriefPrevention/BlockEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/BlockEventHandler.java @@ -741,5 +741,46 @@ public class BlockEventHandler implements Listener //everything else is NOT OK dispenseEvent.setCancelled(true); - } + } + + @EventHandler(ignoreCancelled = true) + public void onTreeGrow (StructureGrowEvent growEvent) + { + //only take these potentially expensive steps if configured to do so + if(!GriefPrevention.instance.config_limitTreeGrowth) return; + + Location rootLocation = growEvent.getLocation(); + Claim rootClaim = this.dataStore.getClaimAt(rootLocation, false, null); + String rootOwnerName = null; + + //who owns the spreading block, if anyone? + if(rootClaim != null) + { + //tree growth in subdivisions is dependent on who owns the top level claim + if(rootClaim.parent != null) rootClaim = rootClaim.parent; + + //if an administrative claim, just let the tree grow where it wants + if(rootClaim.isAdminClaim()) return; + + //otherwise, note the owner of the claim + rootOwnerName = rootClaim.getOwnerName(); + } + + //for each block growing + for(int i = 0; i < growEvent.getBlocks().size(); i++) + { + BlockState block = growEvent.getBlocks().get(i); + Claim blockClaim = this.dataStore.getClaimAt(block.getLocation(), false, rootClaim); + + //if it's growing into a claim + if(blockClaim != null) + { + //if there's no owner for the new tree, or the owner for the new tree is different from the owner of the claim + if(rootOwnerName == null || !rootOwnerName.equals(blockClaim.getOwnerName())) + { + growEvent.getBlocks().remove(i--); + } + } + } + } } diff --git a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java index 50836b3..15dd1e9 100644 --- a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -153,6 +153,8 @@ public class GriefPrevention extends JavaPlugin public HashMap config_seaLevelOverride; //override for sea level, because bukkit doesn't report the right value for all situations + public boolean config_limitTreeGrowth; //whether trees should be prevented from growing into a claim from outside + //reference to the economy plugin, if economy integration is enabled public static Economy economy = null; @@ -351,6 +353,7 @@ public class GriefPrevention extends JavaPlugin this.config_blockSurfaceOtherExplosions = config.getBoolean("GriefPrevention.BlockSurfaceOtherExplosions", true); this.config_blockWildernessWaterBuckets = config.getBoolean("GriefPrevention.LimitSurfaceWaterBuckets", true); this.config_blockSkyTrees = config.getBoolean("GriefPrevention.LimitSkyTrees", true); + this.config_limitTreeGrowth = config.getBoolean("GriefPrevention.LimitTreeGrowth", false); this.config_fireSpreads = config.getBoolean("GriefPrevention.FireSpreads", false); this.config_fireDestroys = config.getBoolean("GriefPrevention.FireDestroys", false); @@ -597,6 +600,7 @@ public class GriefPrevention extends JavaPlugin outConfig.set("GriefPrevention.BlockSurfaceOtherExplosions", this.config_blockSurfaceOtherExplosions); outConfig.set("GriefPrevention.LimitSurfaceWaterBuckets", this.config_blockWildernessWaterBuckets); outConfig.set("GriefPrevention.LimitSkyTrees", this.config_blockSkyTrees); + outConfig.set("GriefPrevention.LimitTreeGrowth", this.config_limitTreeGrowth); outConfig.set("GriefPrevention.FireSpreads", this.config_fireSpreads); outConfig.set("GriefPrevention.FireDestroys", this.config_fireDestroys);