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

Solved Spawn Protection not working

Discussion in 'Development' started by xXNiceAssassinlo YT, May 8, 2018.

  1. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    PHP:
    <?php

    declare(strict_types=1);

    namespace 
    ExonCore\Spawn;

    use 
    pocketmine\event\block\{BlockPlaceEventBlockBreakEvent};
    use 
    pocketmine\event\Listener;

    use 
    ExonCore\Core;

    class 
    EventListener implements Listener{

        private 
    $plugin;

        public function 
    __construct(Core $plugin){
            
    $this->plugin $plugin;
            
    $plugin->getServer()->getPluginManager()->registerevents($this$plugin);
        }

        public function 
    onPlace(BlockPlaceEvent $e){
            
    $player $e->getPlayer();
            
    $x $player->getX();
            
    $y $player->getY();
            
    $z $player->getZ();

            if(
    $x 234 and $x 282 and $y 150 and $x 118 and $z 119 and $z 58){
                
    $e->setCancelled();
                
    $player->sendMessage("You cant place");
            }
        }
    }
    I went on
    234 150 119
    282 118 58

    when i try break inside those coord it will break why...
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    No number matches this criteria
    PHP:
    $z 119 and $z 58
     
  3. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Wat do u mean
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Give me a number that is greater than 119 and at the same time less than 58.
     
  5. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Idk any
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Yup, and that's where the problem lies.
     
    Sandertv likes this.
  7. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    So it’s
    PHP:
      public function onPlace(BlockPlaceEvent $e){
            
    $player $e->getPlayer();
            
    $x $player->getX();
            
    $y $player->getY();
            
    $z $player->getZ();

            if(
    $x 234 and $x 282 and $y 118 and $x 150 and $z 58 and $z 119){
                
    $e->setCancelled();
                
    $player->sendMessage("You cant place");
            }
        }
    }
     
    Muqsit likes this.
  8. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Correct.
     
  9. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Let me try ;D
     
  10. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Still doesn’t work
     
  11. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You mentioned you tried breaking the blocks on the following coordinates:
    234 150 119
    282 118 58

    You will need to replace:
    • > with >=
    • < with <=
    >= stands for "greater than or equal to", <= stands for "lesser than or equal to"
     
  12. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Oh and ALSO, $x, $y and $z are player's coordinates. You should check for the block's coordinates ($event->getBlock()).
     
  13. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    PHP:
    if($x >= 234 and $x <= 282 and $y >= 118 and $x =< 150 and $z >= 58 and $z <= 119){
    err

    Code:
    ParseError: "syntax error, unexpected '<'" (EXCEPTION) in "ExonCore-Main/src/ExonCore/Spawn/EventListener" at line 27
     
  14. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    It's supposed to be <=, not =<
    Source: http://php.net/manual/en/language.operators.precedence.php
     
  15. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    On all?
     
  16. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You wrote it as $x =< 150, it's supposed to be $x <= 150
     
  17. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Whoops
     
  18. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    PHP:
        public function onPlace(BlockPlaceEvent $e){
            
    $player $e->getPlayer();
            
    $block $e->getBlock();
            
    $px $player->getX();
            
    $py $player->getY();
            
    $pz $player->getZ();
            
    $bx $block->getX();
            
    $by $block->getY();
            
    $bz $block->getZ();

            if(
    $px >= 234 and $px <= 282 and $py >= 118 and $px <= 150 and $pz >= 58 and $pz <= 119){
                
    $e->setCancelled();
                
    $player->sendMessage("You cant place");
            }

            if(
    $bx >= 234 and $bx <= 282 and $by >= 118 and $bx <= 150 and $bz >= 58 and $bz <= 119){
                
    $e->setCancelled();
                
    $player->sendMessage("You cant plsace");
            }
        }
    not working again
     
  19. TwistedAsylumMC

    TwistedAsylumMC Slime

    Messages:
    96
    GitHub:
    twistedasylummc
    no point checking for players coords
     
  20. TwistedAsylumMC

    TwistedAsylumMC Slime

    Messages:
    96
    GitHub:
    twistedasylummc
    the problem may be ur checking the blocks x 3 times, try
    PHP:
    if($bx >= 234 and $bx <= 282 and $by >= 118 and $bz >= 58 and $bz <= 119){
                
    $e->setCancelled();
                
    $player->sendMessage("You cant plsace");
            }
     
    xXNiceAssassinlo YT 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.