Replace Block Help!

Discussion in 'Plugin Development' started by TheEpicButterStudios, Oct 19, 2013.

Thread Status:
Not open for further replies.
  1. Hi,

    I am trying to replace a block, here's my code:
    Code:java
    1. public void ExplodeEvent(BlockPlaceEvent event) {
    2.  
    3. if(event.getBlockPlaced().equals(Material.TNT)) {
    4.  
    5. event.getPlayer().getLocation();
    6. event.placeBlock(20);


    Any help is appreciated! Thanks!
     
  2. Offline

    mrCookieSlime Retired Staff

  3. Offline

    Aengo

    Well you can assume what he's trying to do..
    Anyways try this:
    Code:java
    1. @EventHandler
    2. public void TnTReplace(BlockPlaceEvent e){
    3. if(!(e.getBlock().getType().equals(Material.TNT))){
    4. return;
    5. }
    6. e.getBlock().setType(Material.AIR); //Replaces To Air
    7. }
     
  4. Offline

    sgavster

    Code:java
    1. @EventHandler
    2. public void onP(BlockPlaceEvent e)
    3. {
    4. if(e.getBlockPlaced().getType() == Material.TNT)
    5. {
    6. Location l = new Location(e.getBlock().getWorld(), e.getBlock().getX(), e.getBlock().getY(), e.getBlock().getZ());
    7. Block b = l.getBlock();
    8. b.setType(Material.YOUR_MATERIAL);
    9.  
    10. }
    11. }
     
  5. Offline

    mrCookieSlime Retired Staff

    Aengo
    Just wanted to ask, cause maybe he also forgot to implement the Listener and such...
     
  6. I really don't want to display the full code...

    sgavster Will try your code...
     
Thread Status:
Not open for further replies.

Share This Page