I don´t have experience on this kind of objects and, it give me null error. Code: Code (Text): public static ArrayList<Block> getSurroundingBlocks(BlockFace blockFace, Block targetBlock) { ArrayList<Block> blocks = new ArrayList<Block>(); World world = targetBlock.getWorld(); int x = targetBlock.getX(); int y = targetBlock.getY(); int z = targetBlock.getZ(); switch (blockFace) { case UP: case DOWN: { blocks.add(world.getBlockAt(x + 1, y, z)); blocks.add(world.getBlockAt(x - 1, y, z)); blocks.add(world.getBlockAt(x, y, z + 1)); blocks.add(world.getBlockAt(x, y, z - 1)); blocks.add(world.getBlockAt(x + 1, y, z + 1)); blocks.add(world.getBlockAt(x - 1, y, z - 1)); blocks.add(world.getBlockAt(x + 1, y, z - 1)); blocks.add(world.getBlockAt(x - 1, y, z + 1)); break; } case EAST: case WEST: { blocks.add(world.getBlockAt(x, y, z + 1)); blocks.add(world.getBlockAt(x, y, z - 1)); blocks.add(world.getBlockAt(x, y + 1, z)); blocks.add(world.getBlockAt(x, y - 1, z)); blocks.add(world.getBlockAt(x, y + 1, z + 1)); blocks.add(world.getBlockAt(x, y - 1, z - 1)); blocks.add(world.getBlockAt(x, y - 1, z + 1)); blocks.add(world.getBlockAt(x, y + 1, z - 1)); break; } case NORTH: case SOUTH: { blocks.add(world.getBlockAt(x + 1, y, z)); blocks.add(world.getBlockAt(x - 1, y, z)); blocks.add(world.getBlockAt(x, y + 1, z)); blocks.add(world.getBlockAt(x, y - 1, z)); blocks.add(world.getBlockAt(x + 1, y + 1, z)); blocks.add(world.getBlockAt(x - 1, y - 1, z)); blocks.add(world.getBlockAt(x + 1, y - 1, z)); blocks.add(world.getBlockAt(x - 1, y + 1, z)); break; } default: break; } blocks.removeAll(Collections.singleton((Object)null)); return blocks; } The error on console is null and its on line 1115: Code (Text): switch (blockFace) {
I get the blockFace from this method: Code (Text): private HashMap<String, BlockFace> faces = new HashMap<String, BlockFace>(); @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void saveBlockFace(PlayerInteractEvent event) { Player player = event.getPlayer(); BlockFace bf = event.getBlockFace(); if (player != null && bf != null) { String name = player.getName(); faces.put(name, bf); } } public BlockFace getBlockFaceByPlayerName(String name) { return faces.get(name); } I use the 2nd method
Maybe you are getting it before it is put on the map by the listener, the thing you are trying to do is not fail-proof
Solved! The problem was on the HashMap, i changed it to the Main class and now works, thanks to all for the help