1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Getting the placed block and removing it

Discussion in 'Development' started by Karanpatel567, Nov 18, 2017.

  1. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Hey, Does anyone know how to get a block in this case a enderchest and removing as soon as it's placed and it does something? Can you provide me some code?
     
  2. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Easy, just cancel the BlockPlaceEvent if the player placed an Ender Chest:
    PHP:
    public function onBlockPlace(BlockPlaceEvent $event) {
        
    $player $event->getPlayer();
        
    $block_id $block->getId(); // gets the placed block’s ID
        
    if($block_id === 130) { // if player placed 130 ( = Ender Chest)
            
    $event->setCancelled(); // cancel the event.
            
    $player->sendMessage("<message>"); // send the player a message, for example
            // some more code
        
    }
    }
     
    Last edited: Nov 18, 2017
  3. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    But I don't want it to be broken I wanted it to be placed and removed and executed some codes...
     
  4. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    :facepalm: Fixed my message: cancel the BlockPlaceEvent.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.