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

Quitting

Comments in 'Plugin Development' started by Samueljh1, Apr 27, 2015.

?

Am i a noob

  1. YES

    83.3%
  2. NO

    16.7%
  1. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Hey, I'm having some issues with my plugin. I have this code to prevent players logging in from another location:

    PHP:
    public function onPreJoin(PlayerPreLoginEvent $plj){
           
            if(
    array_key_exists($plj->getPlayer()->getName(),$this->pl)){
               
                
    $this->getLogger()->info("§c" $plj->getPlayer()->getName() . " was Kicked. Reason: Already Logged In!");
               
                
    $plj->setCancelled(true);
               
                
    $plj->getPlayer()->kick("Already Logged In!");
               
            }
    $this->pl is an array of players. And beFORE you mention "getOnlinePlayers()", that won't work because its a PRE join event, meaning the player will already be added to that array, making the plugin think that player is online - before he/she can join.

    Anyyyyway, i have a mini mysql system that saves the player's online/offline status. This works fine, but when someone is kicked due to the already logged in thing, an onQuit event is called - which will tell my system that the player is offline. Is there any way to stop the onQuit from being called? (I know setCancelled() :p but i don't want the actual event to be called.) Any ideas or suggestions??

    Thanks :D
  2. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    You could use an if statement to check the reason that the player quit.
    PEMapModder likes this.
  3. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    lol your vote :p and how would you get the "reason"? its not like a kick event
  4. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    /* Fixed :p */

    And i cri for all the noob votes :p
    LDX likes this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    If you use getOnlinePlayers(), this problem will be fixed.
    PHP:
    foreach($this->getServer()->getOnlinePlayers() as $p){
        if(
    $p !== $plj->getPlayer() and strtolower($p->getName()) === strtolower($plj->getPlayer()->getName())){
            
    $plj->getPlayer()->kick("Player already online");
            break;
        }
    }
    iJoshuaHD likes this.

Share This Page

Advertisement