(Solved) Sending Players to Other Servers (BungeeCord)

Discussion in 'BungeeCord Discussion' started by Tyler-Frydenlund, Jun 3, 2017.

Thread Status:
Not open for further replies.
  1. Hi Spigot community,

    So I'm trying to make part of my plugin have a command that can be executed to send players to other servers via bungeecord with out using the log command where they need to remmber the server name. I was going to be really lazy and use the /server command and then the server name but It doesn't work. So I did a bit of research and I can not figure this out. So after they use the /hub command on a server it is supposed to send them to the server that I have named main_server. Issue is I can't figure out how to send them to it. Here is the code for my command and I do realize the formatting sucks and the count down is very in efficient. I will fix those issues latter.

    Code (Text):
    import org.bukkit.Bukkit;
    import org.bukkit.GameMode;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.player.PlayerDropItemEvent;
    import org.bukkit.event.player.PlayerGameModeChangeEvent;
    import org.bukkit.plugin.Plugin;

    import com.google.common.io.ByteArrayDataOutput;
    import com.google.common.io.ByteStreams;


    import net.md_5.bungee.api.ChatColor;



        public class Hub<BungeeCord> implements CommandExecutor {
       
       
       
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

       
       
       
            if(label.equalsIgnoreCase("hub")) {
       
           
                if(sender instanceof Player) {
               
                    Player player = (Player) sender;
                    if(sender instanceof Player){
                        if(player.isOp())
       
            player.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "Sending You to The Main Server..."); //First Message to send to the player letting them know the status

            try {
                    Thread.sleep(1000);
                    player.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "Sending You in 3");//SecondMessage to send to the player letting them know the status
               
                  } catch (InterruptedException ie) {
                    ie.printStackTrace();
                  }
               
                }
           
           
            try {
                Thread.sleep(1000);
                player.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "Sending You in 2");//Message to send to the player letting them know the status
           
              } catch (InterruptedException ie) {
                ie.printStackTrace();
              }
               

            try {
                Thread.sleep(1000);
                player.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "Sending You in 1");

            } catch (InterruptedException ie) {
            ie.printStackTrace();
            }



            try {
                Thread.sleep(100);
                player.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "Sending you..");
           

                BungeeCord teleport = (server);
                ByteArrayDataOutput out = ByteStreams.newDataOutput();
                out.writeUTF("Connect");
                out.writeUTF("main_server");
              player.sendPluginMessage((Plugin) this, "BungeeCord", out.toByteArray());

           
              } catch (InterruptedException ie) {
                ie.printStackTrace();
              }
           
            }
           
           
            } else {
                sender.sendMessage("You can't use this because you not a player ya noob!");
                return false;
            }

        return false;
    }
    }
     
    #1 Tyler-Frydenlund, Jun 3, 2017
    Last edited: Jun 23, 2017
  2. I always use this code, but you have to register the outgoing channel in the main:

    ByteArrayOutputStream b = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(b);
    try {
    out.writeUTF("Connect");
    out.writeUTF(SERVERNAME);
    } catch (IOException eee) {
    Bukkit.getLogger().info("You'll never see me!");
    }
    Bukkit.getPlayer(player).sendPluginMessage(plugin, "BungeeCord", b.toByteArray());
     
  3. Thank you. I'm very new too bungeecord programing. How would I register this in the main class? I know it sounds like im just asking for the code but Im a bit confused.
     
  4. Choco

    Moderator

    You can make your life a bit easier and use the class that I made a little bit ago. It's in my signature, Easy Bungee Messaging Channel
    Code (Java):
    BungeeMessage.CONNECT.send(plugin, thePlayerToSend, "serverToConnectTo");
    With my class, you still have to register the channel, however. To register it, you can read about the Plugin Messaging Channel here
     
    #4 Choco, Jun 6, 2017
    Last edited: Jun 6, 2017
  5. Register in the onEnable() func.

    getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
     
  6. /send <player> <server> ?
    - Thomas
     
    • Optimistic Optimistic x 1
  7. Choco

    Moderator

    You read the thread... correct? The OP wished to send a player to another server using code, and not a command. Either way, I'm pretty sure this thread was resolved after it hasn't been replied to in 2 weeks
     
    • Informative Informative x 1
  8. Hey Im so sorry! I read the thread it worked I forgot to reply to you! Im so sorry!
     
Thread Status:
Not open for further replies.