From a7458bf26192de93f80a544c8899474b346a48db Mon Sep 17 00:00:00 2001 From: cmastudios Date: Fri, 27 Sep 2013 18:12:18 -0500 Subject: [PATCH] Fixes gh-640 - Glassify a list of block types Other block types than AIR and WATER are now automatically "glassified" by the warzone wall guard. --- .../war/structure/ZoneWallGuard.java | 48 ++++++++++++++----- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/war/src/main/java/com/tommytony/war/structure/ZoneWallGuard.java b/war/src/main/java/com/tommytony/war/structure/ZoneWallGuard.java index 666f9dc..daedec0 100644 --- a/war/src/main/java/com/tommytony/war/structure/ZoneWallGuard.java +++ b/war/src/main/java/com/tommytony/war/structure/ZoneWallGuard.java @@ -7,12 +7,12 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; import org.bukkit.entity.Player; import com.tommytony.war.War; import com.tommytony.war.Warzone; import com.tommytony.war.utility.Direction; -import com.tommytony.war.volume.BlockInfo; /** @@ -25,7 +25,20 @@ public class ZoneWallGuard { private Warzone warzone; private Location playerLocation; private BlockFace wall; - private List glassified = new ArrayList(); + private List glassified = new ArrayList(); + public static final Material[] glassifyBlocks = { + Material.AIR, + Material.WATER, + Material.LONG_GRASS, + Material.VINE, + Material.WATER_LILY, + Material.YELLOW_FLOWER, + Material.RED_ROSE, + Material.RED_MUSHROOM, + Material.BROWN_MUSHROOM, + Material.DEAD_BUSH, + Material.SUGAR_CANE_BLOCK + }; public ZoneWallGuard(Player player, War war, Warzone warzone, BlockFace wall) { this.player = player; @@ -161,38 +174,49 @@ public class ZoneWallGuard { } } + public static boolean shouldGlassify(Material material) { + for (Material glassify : glassifyBlocks) { + if (glassify == material) { + return true; + } + } + return false; + } + private void glassify(Block block, BlockFace wall) { // face here means which wall we are working on - if ((block.getTypeId() == Material.AIR.getId() || block.getTypeId() == Material.WATER.getId()) && (this.warzone.getLobby() == null || (this.warzone.getLobby() != null && !this.warzone.getLobby().blockIsAGateBlock(block, wall)))) { + if (shouldGlassify(block.getType()) + && (this.warzone.getLobby() == null || (this.warzone.getLobby() != null && !this.warzone + .getLobby().blockIsAGateBlock(block, wall)))) { if (wall == Direction.NORTH()) { if (this.warzone.getVolume().isNorthWallBlock(block)) { - this.glassified.add(new BlockInfo(block)); + this.glassified.add(block.getState()); block.setType(Material.GLASS); } } else if (wall == Direction.SOUTH()) { if (this.warzone.getVolume().isSouthWallBlock(block)) { - this.glassified.add(new BlockInfo(block)); + this.glassified.add(block.getState()); block.setType(Material.GLASS); } } else if (wall == Direction.EAST()) { if (this.warzone.getVolume().isEastWallBlock(block)) { - this.glassified.add(new BlockInfo(block)); + this.glassified.add(block.getState()); block.setType(Material.GLASS); } } else if (wall == Direction.WEST()) { if (this.warzone.getVolume().isWestWallBlock(block)) { - this.glassified.add(new BlockInfo(block)); + this.glassified.add(block.getState()); block.setType(Material.GLASS); } } else if (wall == BlockFace.UP) { if (this.warzone.getVolume().isUpWallBlock(block)) { - this.glassified.add(new BlockInfo(block)); + this.glassified.add(block.getState()); block.setType(Material.GLASS); } } else if (wall == BlockFace.DOWN) { if (this.warzone.getVolume().isDownWallBlock(block)) { - this.glassified.add(new BlockInfo(block)); + this.glassified.add(block.getState()); block.setType(Material.GLASS); } } @@ -208,11 +232,9 @@ public class ZoneWallGuard { } public void deactivate() { - for (BlockInfo oldBlock : this.glassified) { + for (BlockState oldBlock : this.glassified) { // return to original - Block glassifiedBlock = this.warzone.getWorld().getBlockAt(oldBlock.getX(), oldBlock.getY(), oldBlock.getZ()); - glassifiedBlock.setTypeId(oldBlock.getTypeId()); - glassifiedBlock.setData(oldBlock.getData()); + oldBlock.update(true); } }