1.15.2 Teleport player to Bungeecord server

Discussion in 'Spigot Plugin Development' started by JimiIT92, Jan 27, 2020.

  1. I have an event listener on the PlayerJoin event and what I want to do is teleport the player to a server if some checks are good. So: the player connects to a lobby server, where a plugin does some checks on player join. If all checks are good than the player will be teleported to the main server, otherwise it will stay in the lobby server. What I've done is this, in the main plugin class I registerd the BungeeCord channel
    Code (Java):
    this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
    In the event listener class, after all checks, I than do this
    Code (Java):

    private void teleportToVanilla(Player player) {
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("Connect");
        out.writeUTF("vanilla");
        player.sendPluginMessage(Main.getInstance(), "BungeeCord", out.toByteArray());
    }
     
    I'm sure the method gets called (already added some prints there) but the player doesn't get teleported.
    This is the bungeecord configuration I'm using, but it seems like the server name is correct
    Code (Text):

    prevent_proxy_connections: false
    listeners:
    - query_port: 25577
      motd: '&1Another Bungee server'
      tab_list: GLOBAL_PING
      query_enabled: false
      proxy_protocol: false
      forced_hosts:
        pvp.md-5.net: pvp
      ping_passthrough: false
      priorities:
      - lobby
      - vanilla
      bind_local_address: true
      host: 0.0.0.0:25577
      max_players: 1
      tab_size: 60
      force_default_server: true
    remote_ping_cache: -1
    network_compression_threshold: 256
    permissions:
      default:
      - bungeecord.command.server
      - bungeecord.command.list
      admin:
      - bungeecord.command.alert
      - bungeecord.command.end
      - bungeecord.command.ip
      - bungeecord.command.reload
    log_pings: true
    connection_throttle_limit: 3
    server_connect_timeout: 5000
    timeout: 30000
    player_limit: -1
    ip_forward: false
    groups:
      md_5:
      - admin
    remote_ping_timeout: 5000
    connection_throttle: 4000
    log_commands: false
    stats: 057edd10-6825-40a4-b229-de441fde7111
    online_mode: true
    forge_support: false
    disabled_commands:
    - disabledcommandhere
    servers:
      lobby:
        motd: '&1Just another BungeeCord - Forced Host'
        address: localhost:25565
        restricted: false
      vanilla:
        motd: '&1Vanilla'
        address: localhost:25566
        restricted: false
     
    I'm new to Bungeecord so I might miss something, but I don't understand what could be?
     
  2. How quickly are you trying to send them to the new server?

    https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/#the-bungeecord-plugin-channel
    According to the above, "Keep in mind that you can't send plugin messages directly after a player joins(Eg. in PlayerJoinEvent). You have to include a slight delay."

    This might be the issue, attempt to add a delay when sending them. I see no other error in the code that you have provided which would create the problem you're facing.
     
    • Winner Winner x 1
  3. Aaaah damn, didn't give attention to that part. I moved the logic in a task and called this when the checks are good
    Code (Java):

    Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Teleport(player), 1);
     
    and it works, so even 1 tick of delay does the trick :)
     
    • Like Like x 1
  4. Mark as solved and rate my post if you think I helped :)