send all players to a server

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

  1. hello spigot ! i would like to send all players online in a server to another server, this :

    Code (Text):
     for(Player online : Bukkit.getOnlinePlayers()){
    Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    online.sendPluginMessage(this, "BungeeCord", out.toByteArray());
    or this :

    Code (Text):
       for(Player online : Bukkit.getOnlinePlayers()){
    Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
      ByteArrayDataOutput out = ByteStreams.newDataOutput();
        String on = online.getName();
        online.sendPluginMessage(this, "BungeeCord", out.toByteArray());
    teleport only ONE random player..
    and, this is in a bukkit/spigot plugin but it's a code for bungee so i don't know where create thread xD
    help :(
    #1 azote, Jun 27, 2015
    Last edited: Jun 28, 2015
  2. First of all, you don't need to register the outgoing plugin message for each player, I would put the BungeeCord channel registering in your plugin's onEnable. Second, are you getting any errors in your console? If so, please show the stacktrace.
  3. nothing in the console .. :/ but /send all hub send all players in the hub, in a bukkit plugin can we execute bungee command? :(
  4. Tux


    No, unless you used a solution to link BungeeCord command running with Bukkit like ExecuteEverywhere.

    Anyway, your first set of code should work just fine, with a tweak: register the outcoming plugin message in your onEnable.
  5. it exists? :eek: so, i've register the outcoming message in the onEnable, and, i'ts always the same..
    so i think i use executeeverywhere :p
  6. fuck..
    • Funny Funny x 1
  7. You can do this already i think using the bungee cord send moodle instead of a players name i think u just put *
  8. Since you opened the thread in bungee cord plugin forum there is no Bukkit.getWhatever man... you gotta make ur mind, are you going to make bukkit plugin or bungeecord plugin?

    Now... bungeecord version, it's pretty simple actually:

    Code (Text):
            ServerInfo serverInfo = getProxy().getServers().get("lobby");
            if(serverInfo != null)
                for(ProxiedPlayer proxiedPlayer : getProxy().getPlayers())
    + run that on command and perm for command and that's about it...

    tho hardcoding stuff like server name (lobby) is bad idea (use configs or something)
  9. don't understand..
    i'ts an bukkit plugin
  10. Well besides the outgoing plugin channel registration in the for loop (which you already fixed), the first method is the correct one to use. Why it's not working? I don't know. All I can say is make sure you have a server defined as "hub" in your BungeeCord config.
  11. yes, but only one player are teleported ..
  12. A light bolt just lit above my head! You're sending the player to another server while iterating over bukkit's online player. But after 1 player is sent to another server, it gets removed from Bukkit.getOnlinePlayers() and therefor throwing a ConcurrentModificationException isn't it? Make a field of type Player[] and set it to Bukkit.getOnlinePlayers().toArray(new Player[0]); Then iterate over that one, because when a player is removed from Bukkit.getOnlinePlayers() it's not removed from the array because it's another instance.
    • Agree Agree x 1
  13. solved, a scheduler solved the problem. :)