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

Anti fly err

Discussion in 'Development' started by xXNiceAssassinlo YT, Aug 4, 2018.

  1. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Error:
    PHP:
    [21:55:37] [Server thread/CRITICAL]: Could not tick level "hub"Call to a member function getBlockAt() on null
    [21:55:37] [Server thread/CRITICAL]: Error"Call to a member function getBlockAt() on null" (EXCEPTIONin "src/pocketmine/entity/Entity" at line 1479
    code:
    PHP:
        public function Fly(PlayerMoveEvent $e): void{
            
    $player $e->getPlayer();
            
    $from $e->getFrom();
            
    $to $e->getTo();

            if(
    $player->isFlying()){
                
    $dy = (int)(round($to->getX() - $from->getY(), 3) * 1000);

                if(
    $player->GetInAirTicks() > 20 && $dy >= 0){
                    
    $y $player->getLevel()->getHighestBlockAt(intval($to->getX()), intval($to->getZ()));

                    if(
    $to->getY() - $y){
                        
    $e->setCancelled();
                        
    $player->close(""C::GREEN "Detected: " C::RED "Fly"true);
                    }
                }

                if(
    $dy && $dy 375 == 0){
                    
    $e->setCancelled();
                    
    $player->close(""C::GREEN "Detected: " C::RED "Fly"true);
                }
            }
        }
    i used if($player->isFlying) for testing only xd
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Avoid calling close() on entities inside an event.
     
  3. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    I used $player->kick it still shows that error
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Maybe if instead of using player->kick or close after your checks, you set a variable to true, and at the very end of your method that handles the event, if that variable is true, kick the player. That way the plugin isn't trying to use information from a closed player.
     
    Muqsit likes this.
  5. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    You from a array?

    Like that?
    PHP:
    $hacker = [];

    if(
    in_array($player->getName(), $this->hacker){
    }
     
  6. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Nvm on that, try return; after you kick the player.
     
  7. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Already tried didn’t work
     
  8. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    After both $player->kick()?
     
    xXNiceAssassinlo YT likes this.
  9. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Yup didn’t work I tried
     
  10. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Try scheduling a delayed task (1 tick delay) which kicks the player.
     
    corytortoise 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.