Solved Replacing block on block breakevent

Discussion in 'Plugin Development' started by johnnyD, Jan 30, 2021.

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

    johnnyD

    No idea why this isnt working

    The block being mined isnt replaced with with a sapling.

    Code:
    if(p.getLocation().getBlockX() <= 325 && p.getLocation().getBlockX() >= 306 && p.getLocation().getBlockZ() <= -2 && p.getLocation().getBlockZ() >= -35) {
                if(e.getBlock().getType().equals(Material.LOG)) {
                    Block b = e.getBlock();
                 
                    Block block = p.getWorld().getBlockAt(b.getLocation().getBlockX(), b.getLocation().getBlockY()-1, b.getLocation().getBlockZ());
                    //Location blockLoc = block.getLocation();
                 
                 
                    if(block.getType().equals(Material.DIRT)) {
                     
                        //blockLoc.add(0, 1, 0);
                        //blockLoc.getBlock().setType(Material.COBBLESTONE);
                        e.getBlock().setType(Material.SAPLING);
                        //b.setType(Material.COBBLESTONE);;
                        p.sendMessage("cuch");
                    }
                 
                }
         
            }
    
     
    Last edited: Jan 30, 2021
  2. Offline

    Kars

    Because you are replacing the block that is being broken with a sapling. And it gets broken afterward.
     
  3. Offline

    johnnyD

    Not sure if thats the problem. I tried logging the location then setting the block type. Ex;

    Code:
    Location blockLoc = b.getLocation();
                  
                  
                    if(block.getType().equals(Material.DIRT)) {
                      
                        p.getWorld().getBlockAt(blockLoc).setType(Material.COBBLESTONE);
                        p.sendMessage("cuch");
                    }
    
    EDIT: put a scheduler on it and that fixed it. Thanks for the help!
     
    Last edited: Jan 30, 2021
Thread Status:
Not open for further replies.

Share This Page