Sending Players to Other Servers (BungeeCord)

Discussion in 'Spigot Plugin Help' started by Tyler-Frydenlund, Jun 1, 2017.

  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):
    package commands;

    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;
    }
    }
     
  2. Also I know there are plenty of plugins out there to do this for me but there is a reason for developing, it's to do it yourself.
     
  3. no, you should fix it now. you should not be sleeping the main thread which is processing all main bukkit events and overall management, you'll freeze the server. run a delayed task if you want to simulate a 'wait' but even then, why would u want to do that? :p
     
  4. I should fix that now but it is only freezing the current task at hand so It is not an issue and this class does one thing only. I want to add the delay as a cool little effect. Latter Im going to add nausea and particles.