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

Solved How to cancel players kick for full server slots

Comments in 'Plugin Development' started by R7vmc, Aug 7, 2016.

  1. R7vmc
    Offline

    R7vmc New Member

    Joined:
    Aug 2, 2016
    Posts:
    22
    Minecraft User:
    R7vmc
    hi there.

    I want to know how to cancel players kick if the server slots is full
  2. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    You should not. The max-players value is a hard limit that should never be exceeded. You should set this limit to a larger number, and set a soft limit, and kick normal players if the server player count exceeded the soft limit.
    Also, you should not make the hard limit too large. In the future {{When?}}, PocketMine may preallocate memory to store that number of players. So we may be unhappy if the server always reserved memory for 9950 slots that are not going to be used {{Really that unhappy?}}.
    applqpak and Survingo like this.
  3. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    For a server wich is now dead i coded a VIPjoin plugin. It did hack a bit, and you have to get the idea:
    Just construct this class with your main class of your plugin...
    PHP:
    /* __      _______ _____ _       _
       \ \    / /_   _|  __ (_)     (_)
        \ \  / /  | | | |__) |  ___  _ _ __
         \ \/ /   | | |  ___/ |/ _ \| | '_ \
          \  /   _| |_| |   | | (_) | | | | |
           \/   |_____|_|   | |\___/|_|_| |_|
                           _/ |       
                          |__/       
    */
    class VIPjoin implements Listener{
        public 
    $VIPplayers = [];
        public 
    $enabled true;

        public function 
    __construct($Main){
            
    $this->main $Main;
            
    $this->server $Main->getServer();
            
    $this->server->getPluginManager()->registerEvents($this$this->main);
            
    $this->AnimatedMODTCfg = new Config($this->main->getDataFolder() . "JoinVIPconfig.yml"Config::YAML, array());
            if(
    $this->AnimatedMODTCfg->get("ConfigVersion") != 1){
                
    $this->AnimatedMODTCfg->set('max-normal-players'100);
                
    $this->AnimatedMODTCfg->set('FakeServerList'true);
                
    $this->AnimatedMODTCfg->set('disable'false);
                
    $this->AnimatedMODTCfg->set('debug'true);
                
    $this->AnimatedMODTCfg->set('ConfigVersion'1);
            }
            
    $this->AnimatedMODTCfg->save();
            if(
    $this->AnimatedMODTCfg->get("disable")){
                
    $this->enabled false;
            }
            if(
    $this->AnimatedMODTCfg->get("debug") && $this->enabled){
                
    $this->debug fopen($this->main->getDataFolder().time()."VIPjoinDebug.txt""w");
                if(!
    $this->debug){
                    
    $this->server->getLogger()->critical("ERROR: COULD NOT OPEN/CREATE FILE IN '".$this->main->getDataFolder()."'! Please ensure that the php process has write rights to that directory!");
                    
    $this->server->shutdown();
                }
                
    fwrite($this->debug"initial_info_m-n-p(".$this->AnimatedMODTCfg->get("max-normal-players").")__");
                
    fwrite($this->debug"initial_info_m_p(".$this->server->getMaxPlayers().")__");
                
    fwrite($this->debug"initial_info_fsl(".$this->AnimatedMODTCfg->get("FakeServerList").") \n");
            }
        }

        public function 
    __destruct(){
            if(
    $this->AnimatedMODTCfg->get("debug") && $this->enabled){
                
    fclose($this->debug);
            }
        }

        private function 
    isVIP($player){
            
    $rawPlayerData $this->server->getPluginManager()->getPlugin("PurePerms")->getUserDataMgr()->getData($player);
            return (
    in_array($player->getName(), $this->VIPplayers) || $rawPlayerData["group"] != "Player");
        }

        public function 
    onPreJoin(PlayerPreLoginEvent $event){
            if(
    $this->enabled){
                
    $player $event->getPlayer();
                if(!
    $this->isVIP($player) && count($this->server->getOnlinePlayers()) >= $this->AnimatedMODTCfg->get("max-normal-players")){
                    
    $player->kick("The server is full!"false);
                    
    $event->setCancelled(true);
                    if(
    $this->AnimatedMODTCfg->get("debug")){
                        
    fwrite($this->debug"kick_player_".$player->getName()."_due(SERVER_FULL&&NOT_VIP) \n");
                    }
                }else{
                    if(
    $this->AnimatedMODTCfg->get("debug")){
                        if(!
    $this->isVIP($player)){
                            
    fwrite($this->debug"let_player_".$player->getName()."_in_due(SERVER:NOTFULL) \n");
                        }else{
                            
    fwrite($this->debug"let_player_".$player->getName()."_in_due(SERVER:FULL&&VIP) \n");
                        }
                    }
                }
            }
        }

        public function 
    onQueryRegenerate(QueryRegenerateEvent $event){
            if(
    $this->enabled && $this->AnimatedMODTCfg->get("FakeServerList")){
                
    $event->setMaxPlayerCount($this->AnimatedMODTCfg->get("max-normal-players"));
                if(
    $this->AnimatedMODTCfg->get("debug")){
                    
    fwrite($this->debug"regenerateQuery \n");
                }
            }
        }

        public function 
    onServerCmd(ServerCommandEvent $event){
            
    $msg strtolower($event->getCommand());
            
    $sender $event->getSender();
            
    $doNotCancell false;
            if(
    $msg == "doRemPlayersOverMaxNormal"){
                if(
    $this->server->getOnlinePlayers() >= $this->AnimatedMODTCfg->get("max-normal-players")){
                    foreach(
    $this->server->getOnlinePlayers() as $player){
                        if(
    count($this->server->getOnlinePlayers()) <= $this->AnimatedMODTCfg->get("max-normal-players")){
                            break;
                        }
                        if(
    $this->isVIP($player->getName())){
                            
    $player->kick("You have been kicked!");
                        }
                    }
                }
            }elseif(
    $msg == "disableVIPjoin"){
                
    $this->enabled false;
            }elseif(
    $msg == "enableVIPjoin"){
                
    $this->enabled true;
            }else{
                
    $doNotCancell true;
            }
            if(!
    $doNotCancell){
                
    $event->setCancelled(true);
            }
        }

        public function 
    addVIP($vipPlayerName){
            
    $this->VIPplayers[] = $vipPlayerName;
            return 
    true;
        }
    }
    Last edited: Aug 7, 2016
  4. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    You might want to modify isVIP, it currently checks if you have added your VIP via addVIP(); or just if he is not in the pperm group Player
    please remember that i did this for a server and now just quickly made the cod usable for everyone...
    You just set your server-side player limit to, for example 120 and in the config the limit for 100. Now you have room for 100 normal players and 20 vip players. If fakeServerList is set to true it'll look like this: 102/100, with false it looks like this 102/120. I recommend setting it to true.
  5. R7vmc
    Offline

    R7vmc New Member

    Joined:
    Aug 2, 2016
    Posts:
    22
    Minecraft User:
    R7vmc
    I want this code cause the hosters these days. puts a player limits for servers and I want to make it unlimited :)
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Why won't you do a bit research?
    PHP:
    public function onPlayerKick(PlayerKickEvent $event) {
       
    var_dump($event->getReason());
    }
    Now try to join full server and you'll see what is the reason.
    applqpak, R7vmc and CrazedMiner like this.
  7. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    You're better off storing the data in a database, letting the player join then execute the check and then kick the player if the server is full and they're not a VIP.
  8. R7vmc
    Offline

    R7vmc New Member

    Joined:
    Aug 2, 2016
    Posts:
    22
    Minecraft User:
    R7vmc
    I don't have a full server currently :(
  9. R7vmc
    Offline

    R7vmc New Member

    Joined:
    Aug 2, 2016
    Posts:
    22
    Minecraft User:
    R7vmc
    But thanks this will make the search easier for me :)
  10. R7vmc
    Offline

    R7vmc New Member

    Joined:
    Aug 2, 2016
    Posts:
    22
    Minecraft User:
    R7vmc
    I found a way to do it
  11. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Well, this is being stored in a database this is the low level class and the database classes of the server used to call addVIP() for their stuff
  12. R7vmc
    Offline

    R7vmc New Member

    Joined:
    Aug 2, 2016
    Posts:
    22
    Minecraft User:
    R7vmc
    i got this
    Code:
    string(30) "disconnectionScreen.serverFull"
    so now i should but this right ?
    PHP:
    if($event->getReason() == ("disconnectionScreen.serverFull"){
         
    $event->setCancelled();
    }
  13. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Using PlayerKickEvent basically means bypassing the hard limit. You should not. Read this post I posted 10 hours ago for why not and how otherwise.
  14. R7vmc
    Offline

    R7vmc New Member

    Joined:
    Aug 2, 2016
    Posts:
    22
    Minecraft User:
    R7vmc
    I want this code cause the hosters puts a players slots limit and I can't make it larger or smaller
  15. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Alright using PlayerKickEvent might work for now, but might not work in the future. I already explained why. I believe we all aren't here to help you cheat your hosting service.
  16. R7vmc
    Offline

    R7vmc New Member

    Joined:
    Aug 2, 2016
    Posts:
    22
    Minecraft User:
    R7vmc
    Yea Thx everyone for help
  17. R7vmc
    Offline

    R7vmc New Member

    Joined:
    Aug 2, 2016
    Posts:
    22
    Minecraft User:
    R7vmc
    But will this code work ?
  18. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
  19. R7vmc
    Offline

    R7vmc New Member

    Joined:
    Aug 2, 2016
    Posts:
    22
    Minecraft User:
    R7vmc
  20. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    I'm just answering this thread, don't quote me :p

Share This Page

Advertisement