Fix #838, prevent growth from occupying structures

This prevents leaves/mushroom/etc from growing inside flags,
monuments, cakes, bombs, spawns, etc. Trees can still be grown
around the perimeter of such strucures, but all blocks generated
will be in breakable areas.
This commit is contained in:
Connor Monahan 2017-07-19 18:43:22 -04:00
parent 00ec38c739
commit c5adfa7023
1 changed files with 10 additions and 2 deletions

View File

@ -1,5 +1,8 @@
package com.tommytony.war.event;
import java.util.List;
import java.util.ArrayList;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
@ -466,11 +469,16 @@ public class WarBlockListener implements Listener {
public void onStructureGrowth(final StructureGrowEvent event) {
Warzone zone = Warzone.getZoneByLocation(event.getLocation());
if (zone != null) {
List<BlockState> canceledBlocks = new ArrayList<BlockState>();
for (BlockState state : event.getBlocks()) {
if (!zone.getVolume().contains(state.getLocation())) {
state.setType(Material.AIR);
if (!zone.getVolume().contains(state.getLocation())
|| zone.isImportantBlock(state.getBlock())) {
canceledBlocks.add(state);
}
}
for (BlockState state : canceledBlocks) {
event.getBlocks().remove(state);
}
}
}
}