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

How can I cancel placing block

Discussion in 'Development' started by xXNiceAssassinlo YT, Mar 31, 2018.

  1. iCirgio

    iCirgio Slime

    Messages:
    92
    GitHub:
    lolnova
    LEARN PHP! IM DK SO I APPROVE!
     
  2. korado531m7

    korado531m7 Slime

    Messages:
    77
    GitHub:
    korado531m7
    For example, if you want to cancel between x: 100, y: 5, z: 100 and x: 300, y: 50, z: 300
    PHP:
    public function Place(BlockPlaceEvent $event){
        
    $x $event->getPlayer()->x;
        
    $y $event->getPlayer()->y;
        
    $z $event->getPlayer()->z;
        
    $x1 max("100","300");
        
    $y1 max("5","50");
        
    $z1 max("100","300");
        
    $x2 min("100","300");
        
    $y2 min("5","50");
        
    $z2 min("100","300");
        if(!(
    $x2 <= $x && $x <= $x1 && $y2 <= $y && $y <= $y1 && $z2 <= $z && $z <= $z1)){
            
    $event->setCancelled();
        }
    }
     
    RyanShaw likes this.
  3. KevTastisch

    KevTastisch Creeper

    Messages:
    4
    Do this,
    <?php
    //cancel place Blocks
    namespace Main;

    use pocketmine\plugin\PluginBase;
    use pocketmine\event\Listener;
    use pocketmine\event\block\BlockPlaceEvent;

    class Main extends PluginBase implements Listener {

    public function onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    }

    public function onBlockPlace(BlockPlaceEvent $event){
    $event->setCancelled(true);
    }
    }
     
  4. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    I don't know why would you use min and max if you know the values. Also, why do you write the numbers in quotes?
     
  5. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Wtf you can't break any block with your code.
     
  6. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    understandable*
     
  7. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    Understood by others*. :rolleyes:
     
  8. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    When someone destroys your joke...
     
  9. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Area of which shape? Rectangle, square, circle, sphere, cuboid, polygon...??
     
  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.