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

prevet logging in with name of existing player

Comments in 'Plugin Development' started by Creeperface, Feb 27, 2016.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    i tried this, but it doesn't work if someone log in with my name, he gets kicked, but it unlog me :/
    it seems like PlayerPreLoginEvent is called twice

    PHP:
    public function onPreLogin(PlayerPreLoginEvent $e){
            
    $player $e->getPlayer();

            foreach(
    $this->getServer()->getOnlinePlayers() as $p){
                if(
    $p !== $player && strtolower($player->getName()) === strtolower($p->getName())){
                    
    $e->setCancelled();
                    
    $e->setKickMessage(TextFormat::RED."The same nick is already playing");
                    return;
                }
            }

            
    $this->unauthed[strtolower($player->getName())] = $player;

        }
    i tried change pocketmine method too (method runs before PlayerLoginEvent) but PlayerLoginEvent is still called -,-

    PHP:
    foreach($this->server->getOnlinePlayers() as $p){
                if(
    $p !== $this && strtolower($p->getName()) == strtolower($this->getName())){
                    if(
    $this->kick(TextFormat::RED."The same nick is already playing")){
                        
    $this->close($this->getLeaveMessage(), TextFormat::RED."The same nick is already playing");
                        return;
                    }
                }
            }
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why do you think that it's called twice?
  3. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    because it kicks player and unlog already plaing player
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Unlog? But isn't it something that only your plugin does?
    Add echo lines at critical points to log the control flow.
    applqpak likes this.

Share This Page

Advertisement