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

Solved OnJoin Transfer Player

Discussion in 'Help' started by ced23, Jun 18, 2018.

  1. ced23

    ced23 Spider Jockey

    Messages:
    30
    GitHub:
    Ced2300
    HI,
    I'm trying to create a plugin for my pocketmine server that would have a "proxy" server that redirect players to different lobby. but the problem is that I try a lot of technique but I can't do it.

    PHP:
        public function onLogin(PlayerLoginEvent $event){
            
    $player $event->getPlayer();
            
    $json_string 'http://ced23.alwaysdata.net/';
            
    $jsondata file_get_contents($json_string);
            
    $online1 json_decode($jsondata,1)['Serveur'];
            
    $array = array(19133 => $online1[0],19134 => $online1[1],19135 => $online1[2]);
            if(
    $array[19133] <= 19){
            
    $player->transfer("127.0.0.1"19133);
            }elseif(
    $array[19134] <= 19){
            
    $player->transfer("127.0.0.1"19134);
        }
    }
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    How exactly is it not working?
     
  3. ced23

    ced23 Spider Jockey

    Messages:
    30
    GitHub:
    Ced2300
    Code:
    [09:07:15] [Server thread/INFO]: ced2300[/127.0.0.1:59090] logged out due to transfer
    [09:07:15] [Server thread/CRITICAL]: Error: "Call to a member function getString() on null" (EXCEPTION) in "src/pocketmine/Player" at line 2086
    [09:07:15] [RakLibServer thread/NOTICE]: Blocked 127.0.0.1 for 5 seconds
     
  4. SleepSpace9

    SleepSpace9 Slime

    Messages:
    78
    GitHub:
    sleepspace9
    Maybe it helps to cancel the PlayerLoginEvent when transferring the player otherwhise the server wants to complete the login sequence for a closed player object. Next thing I see is that you want to transfer the player to 127.0.0.1 which would direct him to his own client and not the target server. You need to specify the public IP address or FQDN of the target server.
     
  5. ced23

    ced23 Spider Jockey

    Messages:
    30
    GitHub:
    Ced2300
    How can i cancel PlayerLoginEvent?
     
  6. SleepSpace9

    SleepSpace9 Slime

    Messages:
    78
    GitHub:
    sleepspace9
    Simply add the following line to your code:
    PHP:
    $event->setCancelled();
     
    ced23 likes this.
  7. ced23

    ced23 Spider Jockey

    Messages:
    30
    GitHub:
    Ced2300
    it works!
    But it doesn't transfer me I'm just kick!
    Code:
    [21:48:35] [Server thread/INFO]: ced2300[/127.0.0.1:54038] logged out due to transfer
    Capture.PNG
     
  8. ced23

    ced23 Spider Jockey

    Messages:
    30
    GitHub:
    Ced2300
    Now it works!
    PHP:
        public $lobby1;
        public 
    $lobby2;
        public 
    $lobby3;
        
        public function 
    onEnable()
        {
            
    $this->getLogger()->info("§aStarting Proxy plugin...");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
        
    public function 
    onPreLogin(PlayerPreLoginEvent $event){
            
    $player $event->getPlayer();
            
    $json_string 'http://ced23.alwaysdata.net/';
            
    $jsondata file_get_contents($json_string);
            
    $players1 json_decode($jsondata,1)['Serveur']['19133'];
            
    $players2 json_decode($jsondata,1)['Serveur']['19134'];
            
    $players3 json_decode($jsondata,1)['Serveur']['19135'];
            
    $this->lobby1 $players1;
            
    $this->lobby2 $players2;
            
    $this->lobby3 $players3;
    }

    public function 
    onJoin(PlayerJoinEvent $event){
            
    $player $event->getPlayer();
            if(
    $this->lobby1 <= 19 && !($this->lobby1 == "offline")){
            
    $player->transfer("YOUR.SERVER.IP"19133);
            
    $this->getServer()->broadcastMessage($player->getName()." send to Lobby1 with ".$this->lobby1." players");
            }elseif(
    $this->lobby2 <= 19 && !($this->lobby2 == "offline")){
            
    $player->transfer("YOUR.SERVER.IP"19134);
            
    $this->getServer()->broadcastMessage($player->getName()." send to Lobby2 with ".$this->lobby2." players");
            }elseif(
    $this->lobby3 <= 19 && !($this->lobby3 == "offline")){
                    
    $player->transfer("YOUR.SERVER.IP"19135);
                    
    $this->getServer()->broadcastMessage($player->getName()." send to Lobby3 with ".$this->lobby3." players");
    }
    }
     
    SleepSpace9 likes this.
  9. MadeBali56

    MadeBali56 Creeper

    Messages:
    1
    GitHub:
    madebali56
    Transfer Cepat? Atau Transfer rendah
     
  10. Hariz

    Hariz Creeper

    Messages:
    1
    GitHub:
    harizgaming1
    Gg Bahasa Indo Aowkwk
     
  11. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    Lol, i have an easier Idea for you :) just create timer for player (CoolDown) on join event and then after (5) second transfer player to other servers, (use this if you have Auth plugin in your server).
    or you can just transfer players Random (on Join Event) to other servers easily.
     
  12. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    also you can do it easier, just count players in the Lobby#1 in your server and if players in Lobby#1 is >= 15, transfer therm to Lobby#2 and transfer to other servers. if you need help tag me.
     
    ced23 likes this.
  13. xPen17

    xPen17 Creeper

    Messages:
    3
    GitHub:
    xPen17
    awokawoakwoakwa
     
  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.