javaminecraftbukkitbungeecord

How do I change the server of a player Bungeecord


I was wondering how I can move the target server of the player I dont have any code so far and I have found nothing but I am making a plugin for private use for my Minecraft server network. I do already have a plugin called Command Sync which links my BungeeCord Server and my Spigot Servers with sync console bungee send @p tntwars in vanilla where tntwars is my target server. This is all I know because the Spigot forums are terrible and useless>

How do I move that player to another server?


Solution

  • From Bungee Plugins:

    See https://www.spigotmc.org/wiki/sending-players-between-servers-in-bungeecord/

    ServerInfo target = ProxyServer.getInstance().getServerInfo("Hub");
    player.connect(target);
    

    From Spigot Plugins:

    See https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/#connect

    Connect Example to server. (Used when Example is a player connected to the server sending the command, e.g. 'kick' to server)

     ByteArrayDataOutput out = ByteStreams.newDataOutput();
     out.writeUTF("Connect");
     out.writeUTF("pvp");    
     //applies to the player you send it to. aka Kick To Server.
     Player player = Bukkit.getPlayerExact("Example");
     player.sendPluginMessage(this, "BungeeCord", out.toByteArray());
    

    ConnectOther Example to server. (Used when you need to pull a player out of another server on the network, care should be used to make sure they arn't mid-minigame or something, as you won't necessarily have the server-state context of the player)

     ByteArrayDataOutput out = ByteStreams.newDataOutput();
     out.writeUTF("ConnectOther");
     out.writeUTF("Example");
     out.writeUTF("pvp");
     //Any online player at all.
     //Aka Pull To Server.
     Player player = Iterables.getFirst(Bukkit.getOnlinePlayers(), null);
     player.sendPluginMessage(this, "BungeeCord", out.toByteArray());
    

    You can not send a message to Bungee without any online players!