Replacing Blocks Issues

Discussion in 'Plugin Development' started by WeaselBuilds, Jan 29, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    WeaselBuilds

    Hi there! I'm having a problem with block replacing. For some reason, when this method runs, it doesn't replace the blocks that I need to replace. It also does not return an error.

    Code:
    Show Spoiler
    Code:java
    1. public void wallsFall(){
    2. WorldData w = this.getWorldData();
    3.  
    4. Location l1 = LocationManager.getInstance().getConfigSectLocation(w.getWorld(), w.<ConfigurationSection>get("world.play.1"), false);
    5. Location l2 = LocationManager.getInstance().getConfigSectLocation(w.getWorld(), w.<ConfigurationSection>get("world.play.2"), false);
    6.  
    7. List<Block> blocks = LocationManager.getInstance().getBlocksInLocations(l1, l2);
    8.  
    9. for(Block b : blocks){
    10. for(Material m : BlockHandler.getBannedBlocks()){
    11. if(m == Material.BRICK || m == Material.BRICK_STAIRS) return;
    12.  
    13. if(b.getType().equals(m)){
    14. b.setType(Material.AIR);
    15. }else{
    16. return;
    17. }
    18. }
    19. }
    20. }


    Extra, Just incase:
    Show Spoiler
    Code:java
    1. public List<Block> getBlocksInLocations(Location pt1, Location pt2){
    2. if(!pt1.getWorld().equals(pt2.getWorld()))
    3. throw new IllegalArgumentException("No interdimensional cubes.");
    4. ArrayList<Block> result = new ArrayList<Block>();
    5. Location min = new Location(pt1.getWorld(), Math.min(pt1.getX(), pt2.getX()), Math.min(pt1.getY(), pt2.getY()), Math.min(pt1.getZ(), pt2.getZ()));
    6. Location max = new Location(pt1.getWorld(), Math.max(pt1.getX(), pt2.getX()), Math.max(pt1.getY(), pt2.getY()), Math.max(pt1.getZ(), pt2.getZ()));
    7.  
    8. for(int x = min.getBlockX();x<max.getBlockX();++x){
    9. for(int y = min.getBlockY();y<max.getBlockY();++y){
    10. for(int z = min.getBlockZ();z<max.getBlockZ();++z){
    11. result.add(pt1.getWorld().getBlockAt(x, y, z));
    12. }
    13. }
    14. }
    15. return result;
    16. }


    Help is much appreciated!
    ~Weasel

    Also, the WorldData class can be found here: https://github.com/WeaselBuilds/Wea...net/atvci/noahtemp/walls/world/WorldData.java
     
  2. Offline

    Forseth11

    WeaselBuilds Can you try indenting your blocks of code?
    Possible causes:
    1. blocks empty
    2. wallfall not called
    3. == may cause a problem try .equals()
    4. b type is not equal to m
    5. break naturally is not working.
     
  3. Offline

    WeaselBuilds

    Forseth11 I will try these out. And I tried indenting the code, but it didn't work. And thank you.

    EDIT: It seems that it isn't getting the list or the locations correctly. I tested with the console logging the location and the block type. It logged only once with a location out of the map and the type was a brick (which isn't a block that is to be replaced).
     
Thread Status:
Not open for further replies.

Share This Page