Redirect users with a specific MC version at join to a specific server

Discussion in 'BungeeCord Plugin Development' started by FloxRoxX, Jun 27, 2015.

  1. Hi,
    iam trying to redirect a player with Minecraft 1.7.10 to a specific server on network join.
    This is my code so far:
    Code (Text):
            public void onPostLogin(PostLoginEvent event)
                ProxiedPlayer player = event.getPlayer();
                int version = player.getPendingConnection().getVersion();
                System.out.println("Client version of connecting Player is: "+version);
                if (version == 5)
                        System.out.println("Detected version of 1.7.10, redirecting "+player.getDisplayName()+" to forge Server!");
                        ServerInfo target = ProxyServer.getInstance().getServerInfo("forge");
                        System.out.println("Detected other Client but not 1.7.10");
    This code works on a local network but leads to timeouts on a real server. It also looks like it tries to connect the client twice. I also tried to add somekind of an delay with an scheduler but this did not work. What can i do to cancle the second server connection and / or get rid of this timeouts. Oh and i have to mention, the servers iam connecting to are forge servers, so the connection needs a bit longer than normal.
    Any help appreciated :)
  2. Try to check their server before you transfer them and see if it is already the server they're connected on, if so don't transfer them again.
  3. I use ServerConnectEvent for cases like this. In the Event check if the playre's current server is null (e.getPlayer().getServer() == null) and if it is that means its the first time connecting. And after checking for that just set the server they connect to using e.setTarget()