Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Trying To Detect How Many People In A World

Comments in 'Plugin Development' started by Calrizer, Jan 24, 2015.

  1. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    I'm on Mac, I'm currently using Brackets (Previously Adobe Edge Code), any recommendations??
  2. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Will this work??
    PHP:
    <?php

    namespace PlayerDetectorBeta;

    use 
    pocketmine\level\Level;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\event\player\PlayerRespawnEvent;
    use 
    pocketmine\tile\Sign;
    use 
    pocketmine\plugin\PluginBase;

    class 
    Main extends PluginBase{

        public function 
    onEnable(){
            
    $this->getServer()->getLogger()->info("PlayerDetector Is Now Enabled");
        }
       
        public function 
    onDisable(){
            
    $this->getServer()->getLogger()->info("PlayerDetector Is Now Disabled");
        }

        public function 
    onPlayerJoin(PlayerJoinEvent $event){
           
            foreach(
    $this->getOwner()->getServer()->getLevels() as $ln => $l){
                
    $tl $l->getTiles();
                foreach(
    $tl as $tli => $tile){
                    if(
    $tile instanceof Sign){
                     
                        
    $t $tile->getText();
                     
                        if(
    $t[0] == "[SG]"){
                         
                            
    $world $t[1];
                            
    $name $t[2];
                           
                            if(
    $this->getOwner()->getServer()->isLevelLoaded($world) == true){
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                if(
    $online <= 20){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                                 
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                                 
                                }elseif(
    $online == 0){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                }elseif(
    $online 25 and $online >= 20){
                                    
    $tile->setText("[VIP]" $world $name $online "/24");
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                }elseif(
    $online == 24){
                                    
    $tile->setText("[Full]" $world $name $online "/24");
                                }
                            }
                        }
                    }
                }
            }
        }
       
        public function 
    onPlayerRespawn(PlayerRespawnEvent $event){
           
            foreach(
    $this->getOwner()->getServer()->getLevels() as $ln => $l){
                
    $tl $l->getTiles();
                foreach(
    $tl as $tli => $tile){
                    if(
    $tile instanceof Sign){
                     
                        
    $t $tile->getText();
                     
                        if(
    $t[0] == "[SG]"){
                         
                            
    $world $t[1];
                            
    $name $t[2];
                           
                            if(
    $this->getOwner()->getServer()->isLevelLoaded($world) == true){
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                if(
    $online <= 20){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                                 
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                                 
                                }elseif(
    $online == 0){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                }elseif(
    $online 25 and $online >= 20){
                                    
    $tile->setText("[VIP]" $world $name $online "/24");
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                }elseif(
    $online == 24){
                                    
    $tile->setText("[Full]" $world $name $online "/24");
                                }
                            }
                        }
                    }
                }
            }
        }
       
        public function 
    onPlayerQuit(PlayerQuitEvent $event){
            foreach(
    $this->getOwner()->getServer()->getLevels() as $ln => $l){
                
    $tl $l->getTiles();
                foreach(
    $tl as $tli => $tile){
                    if(
    $tile instanceof Sign){
                     
                        
    $t $tile->getText();
                     
                        if(
    $t[0] == "[SG]"){
                         
                            
    $world $t[1];
                            
    $name $t[2];
                           
                            if(
    $this->getOwner()->getServer()->isLevelLoaded($world) == true){
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                if(
    $online <= 20){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                                 
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                                 
                                }elseif(
    $online == 0){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                }elseif(
    $online 25 and $online >= 20){
                                    
    $tile->setText("[VIP]" $world $name $online "/24");
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                }elseif(
    $online == 24){
                                    
    $tile->setText("[Full]" $world $name $online "/24");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The $online == 0 line will never run because if $online is 0, it must be <= 20.

    Also, use === instead of == as a good practice.
  4. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    In retrospect that one above was a bit noobish so heres a better example but it still doesn't work, help anyone?
    Main:
    PHP:
    <?php

    namespace PlayerDetector;

    use 
    pocketmine\plugin\PluginBase;

    class 
    Main extends PluginBase{

        public function 
    onEnable(){
            
    $this->getServer()->getLogger()->info("PlayerDetector Is Now Enabled");
        }
       
        public function 
    onDisable(){
            
    $this->getServer()->getLogger()->info("PlayerDetector Is Now Disabled");
        }

    }
    Events
    PHP:
    <?php

    namespace PlayerDetector;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\event\player\PlayerRespawnEvent;
    use 
    pocketmine\tile\Sign;
    use 
    pocketmine\plugin\PluginBase;

    class 
    Events implements Listener{
       
        private 
    $plugin;

        public function 
    __construct(PlayerDetector $plugin){
            
    $this->plugin $plugin;
        }

        public function 
    onPlayerJoin(PlayerJoinEvent $event){
           
            foreach(
    $this->getOwner()->getServer()->getLevels() as $ln => $l){
                
    $tl $l->getTiles();
                foreach(
    $tl as $tli => $tile){
                    if(
    $tile instanceof Sign){
                     
                        
    $t $tile->getText();
                     
                        if(
    $t[0] == "[SG]"){
                         
                            
    $world $t[1];
                            
    $name $t[2];
                           
                            if(
    $this->getOwner()->getServer()->isLevelLoaded($world) == true){
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                if(
    $online <= 20){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                                 
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                                 
                                }elseif(
    $online == 0){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                }elseif(
    $online 25 and $online >= 20){
                                    
    $tile->setText("[VIP]" $world $name $online "/24");
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                }elseif(
    $online == 24){
                                    
    $tile->setText("[Full]" $world $name $online "/24");
                                }
                            }
                        }
                    }
                }
            }
        }
       
        public function 
    onPlayerRespawn(PlayerRespawnEvent $event){
           
            foreach(
    $this->getOwner()->getServer()->getLevels() as $ln => $l){
                
    $tl $l->getTiles();
                foreach(
    $tl as $tli => $tile){
                    if(
    $tile instanceof Sign){
                     
                        
    $t $tile->getText();
                     
                        if(
    $t[0] == "[SG]"){
                         
                            
    $world $t[1];
                            
    $name $t[2];
                           
                            if(
    $this->getOwner()->getServer()->isLevelLoaded($world) == true){
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                if(
    $online <= 20){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                                 
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                                 
                                }elseif(
    $online == 0){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                }elseif(
    $online 25 and $online >= 20){
                                    
    $tile->setText("[VIP]" $world $name $online "/24");
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                }elseif(
    $online == 24){
                                    
    $tile->setText("[Full]" $world $name $online "/24");
                                }
                            }
                        }
                    }
                }
            }
        }
       
        public function 
    onPlayerQuit(PlayerQuitEvent $event){
            foreach(
    $this->getOwner()->getServer()->getLevels() as $ln => $l){
                
    $tl $l->getTiles();
                foreach(
    $tl as $tli => $tile){
                    if(
    $tile instanceof Sign){
                     
                        
    $t $tile->getText();
                     
                        if(
    $t[0] == "[SG]"){
                         
                            
    $world $t[1];
                            
    $name $t[2];
                           
                            if(
    $this->getOwner()->getServer()->isLevelLoaded($world) == true){
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                if(
    $online <= 20){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                                 
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                                 
                                }elseif(
    $online == 0){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                }elseif(
    $online 25 and $online >= 20){
                                    
    $tile->setText("[VIP]" $world $name $online "/24");
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                }elseif(
    $online == 24){
                                    
    $tile->setText("[Full]" $world $name $online "/24");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
  5. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Ok cheers I will wack it in when I get home :)
  6. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Says
    "Fatal error: Cannot access parent:: when current class scope has no parent"
    Something to do with this line:
    PHP:
    parent::__construct($plugin);
  7. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Cheers that did the trick, all is working now!
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No, it will break other thing that you didn't notice.
    Are you sure your class extends PluginTask?

Share This Page

Advertisement