Solved troubles with connecting players to lobby

Discussion in 'BungeeCord Plugin Development' started by Arjan, Sep 5, 2015.

  1. Hi,

    So I have written some code to reconnect everyone from a server back to the lobby although its not working particularly great.
    Sometimes I get kicked completely off the network with the message 'The host closed the connect' and sometimes I do get reconnected although then it says 'Already connecting to Lobby'. (I do get connected though)

    This is what I'm using:
    Code (Text):

    ByteArrayOutputStream b = new ByteArrayOutputStream();
                    DataOutputStream out = new DataOutputStream(b);
                   
                    try {
                        out.writeUTF("Connect");
                        out.writeUTF("lobby");
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                   
                    for(Player p : Bukkit.getOnlinePlayers()){      
                        p.sendMessage(ChatColor.STRIKETHROUGH + StringUtils.repeat(" ", 80));
                        p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + ChatColor.UNDERLINE + "You were connected to the lobby");
                        p.sendMessage(ChatColor.STRIKETHROUGH + StringUtils.repeat(" ", 80));
                       
                        try{
                            p.getServer().sendPluginMessage(plugin, "BungeeCord", b.toByteArray());
                        }catch(Exception e){
                            e.printStackTrace();
                        }
                    }
                    Bukkit.shutdown();
     
  2. Teg

    Teg
    Supporter

    You have to set a delayed task to call Bukkit.shutdown(). Players won't be moved to the lobby server instantly.
     
  3. Thanks, problem solved.