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

Kick players in specific level

Comments in 'Plugin Development' started by TonyDroide, Jan 31, 2016.

  1. TonyDroide
    Offline

    TonyDroide Active Member Plugin Developer

    Joined:
    Jun 5, 2015
    Posts:
    122
    Plugins:
    1
    Minecraft User:
    TonyDroidd
    I want to kick players in specific level, but my code does not works xD
    does not generate error messages and crash dumps :/ only not works

    ¿someone can help me?

    PHP:
        public function kickPlayersInLevel($world$sender){
            
    $level $this->getServer()->getLevelByName($world);
            if(!
    $this->getServer()->isLevelLoaded($world)){
                
    $sender->sendMessage(TextFormat::RED "World " $world " is not loaded, load using /lm load <levelname>");
                return 
    false;
            }
            if(!
    $level instanceof Level){
                
    $sender->sendMessage(TextFormat::RED "World " $world " not found");
                return 
    false;
            }
            foreach(
    $level->getPlayers() as $pl){
                if(
    $pl === null){
                    
    $sender->sendMessage("There are no player in level " $world);
                    return 
    false;
                }
                
    $sender->sendMessage(TextFormat::WHITE "Kicked " count($pl) . " players in level " $world);
                
    $pl->kick(TextFormat::YELLOW "Kicked by admin"false);
            }
            return 
    true;
        }
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    error?
  3. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    This should work, edit it as you want
    PHP:
    public function kickByLevel($level)
    {
    if((
    $level $this->getServer()->getLevelByName($level)) instanceof Level and $level->isLoaded()){
    foreach(
    $level->getPlayers() as $p){
    if(
    $p != null){
    $p->kick();
    }
    }
    }
    * This is executed by a command, no? Are you sure that the problem isn't into the command?
    Last edited: Jan 31, 2016
  4. TonyDroide
    Offline

    TonyDroide Active Member Plugin Developer

    Joined:
    Jun 5, 2015
    Posts:
    122
    Plugins:
    1
    Minecraft User:
    TonyDroidd
  5. TonyDroide
    Offline

    TonyDroide Active Member Plugin Developer

    Joined:
    Jun 5, 2015
    Posts:
    122
    Plugins:
    1
    Minecraft User:
    TonyDroidd
    Nope :/
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    // $pl is instanceof Player not Player[]
    count($pl);
    // function 'count' only works on  arrays
    And why don't you pass object Level instead of name?
    PHP:
    /**
    * @param Level $world
    * @return int or false
    */
    public function kickPlayersByLevel(Level $world){
    if(!
    $world->isLoaded()) return false;
    if(
    count($world->getPlayers()) <= 0) return false;
    $c 0;
    foreach(
    $world->getPlayers() as $p){
    $p->kick("Undefined Reason!"); $c++;
    }
    return 
    $c;
    }
    PEMapModder and PocketKiller like this.
  7. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    What's the '$c' for?
  8. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Kicked player count.
  9. TonyDroide
    Offline

    TonyDroide Active Member Plugin Developer

    Joined:
    Jun 5, 2015
    Posts:
    122
    Plugins:
    1
    Minecraft User:
    TonyDroidd
    not works, is the same issuse
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Please do not reply with invalid answers. $pl is a Player|null, and in no way is it possible that it is an array. Please delete invalid posts.

Share This Page

Advertisement