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

Set max players inside a plugin

Discussion in 'Development' started by EndermannbugZJFC, Apr 12, 2020.

  1. EndermannbugZJFC

    EndermannbugZJFC Slime

    Messages:
    84
    GitHub:
    endermanbugzjfc
    Hi, I want to ask if it is possible to set the max players inside a plugin. Because I tried with setConfigInt and getConfigInt but it can only get the max players and can't set it. Please help.
    PHP:
    $cmd preg_replace("/[^a-z]+/"""strtolower($cmd->getName()));
            if (
    $cmd === "setmaxplayers" || $cmd === "maxjoin") {
                if (!isset(
    $args[0])) {
                    
    $this->getLogger()->notice("Debug: Original max players: " $this->getServer()->getConfigInt("max-players"));
                    return 
    true;
                }
                
    $args[0] = intval($args[0]);
                if (!
    is_integer($args[0])) {
                    return 
    false;
                }
                
    $this->getServer()->setConfigInt("max-players"$args[0]);
                
    $this->getLogger()->notice("Debug: Max players have been set to: " $args[0]);
                
    $sender->sendMessage(TF::GREEN "Max players have been set to: " $args[0]);
                
    $this->getServer()->doAutoSave();
                return 
    true;
            }
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    PHP:
    public $playerCount 20;

    public function 
    onQuery(QueryRegenerateEvent $event) {
       
    $event->setMaxPlayerCount($this->playerCount);
    }
     
  3. EndermannbugZJFC

    EndermannbugZJFC Slime

    Messages:
    84
    GitHub:
    endermanbugzjfc
    Really thinks!
    This is how I get more player slots on free pocketmine servers Lmao.
     
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Nope. That just replaces displayed count. Server will still kick players if there were more than max player count specified in server.properties.
     
  5. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    I wrote plugin for that 2 years ago. I'm not sure it still works, if it's even worked... But this function which cancells kicking player seems right.
     
  6. EndermannbugZJFC

    EndermannbugZJFC Slime

    Messages:
    84
    GitHub:
    endermanbugzjfc
    oh ok
     
  7. EndermannbugZJFC

    EndermannbugZJFC Slime

    Messages:
    84
    GitHub:
    endermanbugzjfc
    but actually ty for the function
     
  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.