Check on what material you place block

Discussion in 'Plugin Development' started by HerobrineHunterH, May 29, 2015.

Thread Status:
Not open for further replies.
  1. Hey guys!

    i'd like to know how to check on what material a block is being placed
    i tried this
    public void onBlockPlace(BlockPlaceEvent e){
    Player player = e.getPlayer();
    Location location = e.getBlock().getLocation();
    if (new Location(location.getWorld(), location.getX(), location.getY() - 1, location.getZ()).getBlock().getType() == Material.GRASS);
    player.sendMessage("You placed it on grass");
    }
    }
    But it just said "You placed it on grass" wherever i place a block
     
  2. Offline

    mine-care

    @HerobrineHunterH
    Mhm
    Umm please post code on [code ] brackets to help us read it,
    Anyway it is a syntax error, you have an extra semicolon (;) next to your if making it practically useles
    Also an efficiency tip: don't create a second location object in every block place instead use location.add(0,-1,0) and that will do exay the same without creating the object.
     
  3. You could use this:
    Code:
    @EventHandler
    public void onBlockPlace(BlockPlaceEvent e){
           Block b = e.getBlock().getWorld().getBlockAt(e.getBlock().getX(), e.getBlock().getY()-1, e.getBlock().getZ());
           if(b.getType().equals(Material.WHATEVER)){
                   // Do whatever
           }
    }
    
     
  4. wow thanks for the quick response!
    And sorry i'm new here didnt know to you could use
    Code:
    
    
     
  5. Offline

    Konato_K

  6. Yes but i only want to check for when a block is placed above another
     
Thread Status:
Not open for further replies.

Share This Page