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

not working

Discussion in 'Development' started by xXNiceAssassinlo YT, Apr 1, 2018.

  1. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    PHP:
        public function onBreak(BlockBreakEvent $event) : void{
            
    $x1 = -144;
            
    $x2 69.8795;
            
    $y1 0;
            
    $y2 125.1111;
            
    $z1 70;
            
    $z2 = -140.3012;

            
    $player $event->getPlayer();
            
    $block $event->getBlock();

            if(!
    $player->isOp()){
                if(
    $block->getLevel()->getName() == $this->plugin->getServer()->getLevelByName("world")){
                    if(
    $block->getX() >= -144 and $block->getX() <= 69.8795 and $block->getX() >= -144 and $block->getZ() >= 70 and $block->getZ() <= -140.3012){
                        
    $player->sendPopup(C::RED "You can't build in spawn.");
                        
    $event->setCancelled(true);
                    }
                }
            }
        }
    No Eror
     
  2. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    1.In PHP you don't need ": void" if the method returns nothing.
    2.You are comparing a level name to a level instance.
    3.You don't use the variables you've defined.
    4.You compare the block's x to your values 3 times and don't compare it's y to anything at all.
     
    GamakCZ likes this.
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Don't need ≠ need to remove. It is a good practice to have void return type. Whybare you complaining?
     
  4. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    Hm, I didn't know that. That is about the void return type in PHP. I thought it may cause some runtime errors. Sorry.
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Bad code often comes from poor error handling, and type hinting (": void") helps in exposing errors.
     
  6. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    I understand it, I just didn't know about this exact return type and thought OP has mixed it in from some other language he may use.
     
    Muqsit likes this.
  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.