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

ban when player leaves

Discussion in 'Facepalm' started by Levi, Aug 14, 2017.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    thx jasonw
     
    Last edited: Aug 14, 2017
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    On a PlayerQuitEvent you can check if the freeze array using isset()
    PHP:
    public function onQuit(PlayerQuitEvent $e){
        if(isset(
    $this->freeze[$event->getPlayer()->getName()])) // no copying or it will fail :P
            
    $e->getPlayer()->setBanned(true);
    }
     
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Help I got clear sky lite crash undefined variable on line 42 in my plugin
    PHP:
    if(isset($this->freeze[$event->getPlayer()->getName()])) // no copying or it will fail :P
    Me not know PHP so I copy code help pls sry for bad eng thx
     
    VCraft, Palente, jasonwynn10 and 5 others like this.
  4. DayKoala

    DayKoala Silverfish

    Messages:
    22
    GitHub:
    daykoala
    PHP:
    public function onQuit(PlayerQuitEvent $event){
            
    $player $event->getPlayer();
            if(isset(
    $this->ban[$player->getName()])){
               
    $this->getServer()->getNameBans()->addBan($player->getName());
            }
        }
    Try this
     
  5. Jonas

    Jonas Baby Zombie

    Messages:
    192
    You can try this:
    PHP:
    public $ban = array();
        public function 
    onQuit(PlayerQuitEvent $e){
            if(
    in_array($e->getPlayer()->getName(), $this->ban)){
                
    $this->getServer()->getNameBans()->addBan($e->getPlayer()->getName());
            }
        }
     
  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.