diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java b/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java index 5358e3b..2f6b053 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java @@ -1,6 +1,7 @@ package world.bentobox.greenhouses.greenhouse; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -16,15 +17,9 @@ import org.bukkit.util.Vector; * */ public class Roof extends MinMaxXZ { - private final Location location; - private int height; - private boolean roofFound; - - /** - * @return a list of valid roof blocks - */ - public static List getRoofBlocks() { - return Arrays.stream(Material.values()) + public static final List ROOF_BLOCKS; + static { + List r = Arrays.stream(Material.values()) .filter(Material::isBlock) // Blocks only, no items .filter(m -> !m.name().contains("DOOR")) // No doors .filter(m -> m.name().contains("TRAPDOOR") // All trapdoors @@ -32,7 +27,11 @@ public class Roof extends MinMaxXZ { || m.equals(Material.HOPPER) // Hoppers || m.equals(Material.GLOWSTONE)) // Glowstone .collect(Collectors.toList()); + ROOF_BLOCKS = Collections.unmodifiableList(r); } + private final Location location; + private int height; + private boolean roofFound; /** * Finds a roof from a starting location under the roof and characterizes it @@ -60,10 +59,10 @@ public class Roof extends MinMaxXZ { if (!((x > loc.getBlockX() - radius && x < loc.getBlockX() + radius) && (z > loc.getBlockZ() - radius && z < loc.getBlockZ() + radius))) { Block b = world.getBlockAt(x, roofY, z); - if (!Walls.isWallBlock(b.getType())) { + if (!Walls.WALL_BLOCKS.contains(b.getType())) { // Look up for (int y = roofY; y < world.getMaxHeight(); y++) { - if (getRoofBlocks().contains(world.getBlockAt(x,y,z).getType())) { + if (ROOF_BLOCKS.contains(world.getBlockAt(x,y,z).getType())) { roofFound = true; loc = new Location(world,x,y,z); break; @@ -125,7 +124,7 @@ public class Roof extends MinMaxXZ { Location maxz = height.toLocation(world); Location minz = height.toLocation(world); int limit = 0; - while (getRoofBlocks() + while (ROOF_BLOCKS .contains(world.getBlockAt(maxx).getType()) && limit < 100) { limit++; maxx.add(new Vector(1,0,0)); @@ -134,7 +133,7 @@ public class Roof extends MinMaxXZ { maxX = maxx.getBlockX()-1; } - while (getRoofBlocks().contains(world.getBlockAt(minx).getType()) && limit < 200) { + while (ROOF_BLOCKS.contains(world.getBlockAt(minx).getType()) && limit < 200) { limit++; minx.subtract(new Vector(1,0,0)); } @@ -142,7 +141,7 @@ public class Roof extends MinMaxXZ { minX = minx.getBlockX() + 1; } - while (getRoofBlocks().contains(world.getBlockAt(maxz).getType()) && limit < 300) { + while (ROOF_BLOCKS.contains(world.getBlockAt(maxz).getType()) && limit < 300) { limit++; maxz.add(new Vector(0,0,1)); } @@ -150,7 +149,7 @@ public class Roof extends MinMaxXZ { maxZ = maxz.getBlockZ() - 1; } - while (getRoofBlocks().contains(world.getBlockAt(minz).getType()) && limit < 400) { + while (ROOF_BLOCKS.contains(world.getBlockAt(minz).getType()) && limit < 400) { limit++; minz.subtract(new Vector(0,0,1)); } diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/Walls.java b/src/main/java/world/bentobox/greenhouses/greenhouse/Walls.java index 825b347..1fe6598 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/Walls.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/Walls.java @@ -1,6 +1,7 @@ package world.bentobox.greenhouses.greenhouse; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -10,15 +11,9 @@ import org.bukkit.World; import org.bukkit.block.BlockFace; public class Walls extends MinMaxXZ { - private int floor; - - private static final List ORDINALS = Arrays.asList(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST); - - /** - * @return list of valid wall blocks - */ - public static List getWallBlocks() { - return Arrays.stream(Material.values()) + public static final List WALL_BLOCKS; + static { + List w = Arrays.stream(Material.values()) .filter(Material::isBlock) // Blocks only, no items .filter(m -> !m.name().contains("TRAPDOOR")) // No trap doors .filter(m -> m.name().contains("DOOR") // All doors @@ -26,8 +21,13 @@ public class Walls extends MinMaxXZ { || m.equals(Material.HOPPER) // Hoppers || m.equals(Material.GLOWSTONE)) // Glowstone .collect(Collectors.toList()); + WALL_BLOCKS = Collections.unmodifiableList(w); } + private int floor; + + private static final List ORDINALS = Arrays.asList(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST); + public Walls(Roof roof) { // The player is under the roof // Assume the player is inside the greenhouse they are trying to create @@ -64,25 +64,25 @@ public class Walls extends MinMaxXZ { switch (bf) { case EAST: // positive x - if (getWallBlocks().contains(world.getBlockAt(x, y, z).getRelative(bf).getType())) { + if (WALL_BLOCKS.contains(world.getBlockAt(x, y, z).getRelative(bf).getType())) { stopMaxX = true; } break; case WEST: // negative x - if (getWallBlocks().contains(world.getBlockAt(x, y, z).getRelative(bf).getType())) { + if (WALL_BLOCKS.contains(world.getBlockAt(x, y, z).getRelative(bf).getType())) { stopMinX = true; } break; case NORTH: // negative Z - if (getWallBlocks().contains(world.getBlockAt(x, y, z).getRelative(bf).getType())) { + if (WALL_BLOCKS.contains(world.getBlockAt(x, y, z).getRelative(bf).getType())) { stopMinZ = true; } break; case SOUTH: // positive Z - if (getWallBlocks().contains(world.getBlockAt(x, y, z).getRelative(bf).getType())) { + if (WALL_BLOCKS.contains(world.getBlockAt(x, y, z).getRelative(bf).getType())) { stopMaxZ = true; } break; @@ -136,7 +136,7 @@ public class Walls extends MinMaxXZ { wallBlockCount = 0; for (int x = minX; x <= maxX; x++) { for (int z = minZ; z <= maxZ; z++) { - if (getWallBlocks().contains(world.getBlockAt(x, y, z).getType())) { + if (WALL_BLOCKS.contains(world.getBlockAt(x, y, z).getType())) { wallBlockCount++; } } @@ -154,10 +154,6 @@ public class Walls extends MinMaxXZ { return floor; } - public static boolean isWallBlock(Material blockType) { - return getWallBlocks().contains(blockType); - } - /** * @return width of the space */ diff --git a/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java b/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java index 60d0058..0b9a69f 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java +++ b/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java @@ -80,8 +80,8 @@ public class GreenhouseFinder { } else { // Check just the walls if (y == roof.getHeight() || x == minX || x == maxX || z == minZ || z== maxZ) { - if ((y != roof.getHeight() && !Walls.getWallBlocks().contains(blockType)) - || (y == roof.getHeight() && !Roof.getRoofBlocks().contains(blockType))) { + if ((y != roof.getHeight() && !Walls.WALL_BLOCKS.contains(blockType)) + || (y == roof.getHeight() && !Roof.ROOF_BLOCKS.contains(blockType))) { //logger(2,"DEBUG: bad block found at " + x + "," + y+ "," + z + " " + blockType); if (blockType == Material.AIR) { airHole = true;