out.writeUTF Doenst connect me to the Server

Discussion in 'Spigot Plugin Development' started by GoRoK, Jun 23, 2016.

  1. Code (Text):

    else if(e.getCurrentItem().getType() == Material.SAPLING)
                {
                    p.closeInventory();
                    ByteArrayOutputStream b = new ByteArrayOutputStream();
                    DataOutputStream out = new DataOutputStream(b);
                    try {
                        out.writeUTF("Connect");
                        out.writeUTF("Hub2");
                    } catch (IOException e1) {
                        e1.printStackTrace();}
                    p.sendMessage("Connecting to ' HUB 1 '");  
                    p.sendPluginMessage(plugin, "BungeeCord", b.toByteArray());
                }
     
    Thats the code im using.
    The BungeeCord Config is:
    Code (Text):

    ip_forward: true
    network_compression_threshold: 256
    stats: cd4c3b80-8bda-46b6-bb63-682ba51fea00
    permissions:
      default:
      - bungeecord.command.list
      admin:
      - bungeecord.command.alert
      - bungeecord.command.end
      - bungeecord.command.ip
      - bungeecord.command.reload
      - bungeecord.command.send
      - bungeecord.command.list
      - bungeecord.command.server
      - bat.admin
      - report.listreports
      - report.acceptreport
      - report.receivereport
      - report.detailreport
      - report.setstatus
      - easyrp.notify
      mod:
      - bat.admin
      - bungeecord.command.list
      - bungeecord.command.server
      - bungeecord.command.send
      - report.listreports
      - report.acceptreport
      - report.receivereport
      - report.detailreport
      - report.setstatus
      - easyrp.notify
      builder:
      - bungeecord.command.list
      - bungeecord.command.server
    groups:
      NiroxYT:
      - admin
      ImSimonOrginal:
      - admin
      Phenom:
      - admin
      GoRoK:
      - admin
    servers:
      Build[Reeps]:
        address: 213.202.228.191:25580
        restricted: false
        motd: '&1Build[Reeps]'
      1VS1[1]:
        address: 213.202.228.191:25590
        restricted: false
        motd: '&11VS1[1]'
      Hub1:
        address: 213.202.228.191:25595
        restricted: false
        motd: '&1Hub1'
      1VS1[2]:
        address: 213.202.228.191:25585
        restricted: false
        motd: '&1SG1'
      GunGame:
        address: 213.202.228.191:25560
        restricted: false
        motd: '&1GunGame'
      BW1:
        address: 213.202.228.191:25530
        restricted: false
        motd: '&1BW1'
      SkyBlock:
        address: 213.202.228.191:25535
        restricted: false
        motd: '&1SkyBlock'
      Quest:
        address: 213.202.228.191:25525
        restricted: false
        motd: '&1TestServer'
      Hub2:
        address: 213.202.228.191:25520
        restricted: false
        motd: '&1Hub2'
      Hub3:
        address: 213.202.228.191:25540
        restricted: false
        motd: '&1Hub3'
      QSG[1]:
        address: 213.202.228.191:25555
        restricted: false
        motd: '&cRESTART'
      MineWar:
        address: 213.202.228.191:25570
        restricted: false
        motd: '&1MineWar'
      SJ1:
        address: 213.202.228.191:25575
        restricted: false
        motd: '&1SJ1'
      SW1:
        address: 213.202.228.191:25545
        restricted: false
        motd: '&1SW1'
      SCG1:
        address: 213.202.228.191:25510
        restricted: false
        motd: '&1SCG1'
      RL:
        address: 213.202.228.191:25505
        restricted: false
        motd: '&1RL'
    timeout: 0
    listeners:
    - max_players: 80
      host: 213.202.228.191:25565
      bind_local_address: true
      ping_passthrough: false
      tab_list: SERVER
      forced_hosts:
        mc.nirox.eu: Hub1
      tab_size: 60
      force_default_server: false
      motd: '&1Nirox.EU'
      query_enabled: false
      query_port: 25565
      priorities:
      - Hub1
      - Hub1
      - Hub1
      - Hub1
    player_limit: -1
    online_mode: true
    log_commands: false
    disabled_commands:
    - disabledcommandhere
    connection_throttle: -1
     
    Im completly new to those things, so please no flamerino and learn Javarino in here. Thanks!
     
  2. MiniDigger

    Supporter

    I typically use this, but yours should work fine too
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeUTF("Connect");
    out.writeUTF("Hub2");
    p.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());

    you should make sure that the code actually gets executed. does the inventory gets closed?
     
  3. Yes, the message: " p.sendMessage("Connecting to ' HUB 1 '"); " gets executed as well. So it works... Ingame it says "Connection failed. Server not found!"
     
  4. MiniDigger

    Supporter

    did you restart bungee after you added the hub2 server?
     
  5. [​IMG]
    The config is old, its added since like 2 weeks.. Started the whole root server new like 15 min ago. So..
    http://imgur.com/rT4mrGW
     
  6. MiniDigger

    Supporter

    your plugin is fine, the error is caused by bungee. can you switch to the server hub2 using /server?
     
  7. Positive.
     
  8. Maybe try GetServers and then display the response and see if Hub2 is in the response
     
  9. Dum question, how to do that?
     
  10. It is explained here how to recieve the respone.
     
  11. Cant use "in", are those the correct imports:
    Code (Text):

    import java.io.ByteArrayOutputStream;
    import java.io.DataOutputStream;
    import java.io.IOException;
     
     
  12. You are missing one: ByteArrayDataInput
     
  13. Cant use the readUTF for some reason? in cannot be resolved
    at the command:
    Code (Text):
     String[] serverList = in.readUTF().split(", ");
    in is red. No import possibility..
     
  14. I see the problem, read the start of the wiki
     
  15. So, i think i got it.
    If i do:
    Code (Text):

    public String[] serverList;
        public void onPluginMessageReceived(String channel, Player player, byte[] message) {
           if (!channel.equals("BungeeCord")) {
             return;
           }
           ByteArrayDataInput in = ByteStreams.newDataInput(message);
           serverList = in.readUTF().split(", ");
           System.out.println(serverList);
           player.sendMessage(serverList);
           
         }
     
    I dont get a message, and the console isnt receiving anything as well..
     
  16. Did you register the Outgoing messages ?