hey guys im trying to make a method wich takes 2 coordinates iterates through the Layers bewteen the coordinates, iterates through the rows in each layer, iterates through each block in each row and if the block isnt air it add the block to a blockList My code: Code (Text): public static List<Block> getBlocks() { Location loc1 = Main.loc1; Location loc2 = Main.loc2; Location loc3 = loc1; List<Block> blockList = null; if (loc1.getBlockY() > loc2.getBlockY()) { for (int i = loc1.getBlockY(); i != loc2.getBlockY(); i--) { for(int a = loc1.getBlockX(); a != loc2.getBlockX(); a--) { for(int z = loc1.getBlockZ(); z != loc2.getBlockZ(); z++) { loc3 = new Location(loc1.getWorld(), a, i, z); if(loc3.getBlock().getType() != Material.AIR) { blockList.add(loc3.getBlock()); } } } } } return blockList; }
Im not even answering to you, Im completing your comment lol. Btw, yes Material.AIR returns null and so does Material.BARRIER when you check for a block. But yes, the list is null and hasnt been initialized
getType is annotated NotNull, hence never returns null. https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/Block.html#getType--
Once again, annotated NotNull https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Location.html#getBlock--
It works now so now my code looks like this: Code (Text): public class Methods { public static void set() { List<Block> blockList = getBlocks(); for(Block b : blockList) { b.setType(Material.DIAMOND_BLOCK); } } public static List<Block> getBlocks() { Location loc1 = Main.loc1; Location loc2 = Main.loc2; Location loc3 = loc1; List<Block> blockList = new ArrayList<Block>(); if (loc1.getBlockY() > loc2.getBlockY()) { for (int i = loc1.getBlockY(); i != loc2.getBlockY(); i--) { for(int a = loc1.getBlockX(); a != loc2.getBlockX(); a--) { for(int z = loc1.getBlockZ(); z != loc2.getBlockZ(); z++) { loc3 = new Location(loc1.getWorld(), a, i, z); Bukkit.broadcastMessage("" + loc3.getBlockX() + " "+ loc3.getBlockY() + " "+ loc3.getBlockZ() + " "); if(loc3.getBlock() != null) { blockList.add(loc3.getBlock()); } } } } } return blockList; } }