Server MOTD Pinging Help

Discussion in 'Plugin Development' started by CaptainCoder, Jun 6, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    CaptainCoder

    Hi,

    I have 2 servers, the first server pings the second and gets its motd, with this code:
    Code:java
    1. public static String getMOTD(String ip, int port) {
    2. try {
    3. Socket sock = new Socket();
    4. sock.setSoTimeout(100);
    5. sock.connect(new InetSocketAddress(ip, port), 100);
    6.  
    7. DataOutputStream out = new DataOutputStream(sock.getOutputStream());
    8. DataInputStream in = new DataInputStream(sock.getInputStream());
    9.  
    10. out.write(0xFE);
    11.  
    12. int b;
    13. while ((b = in .read()) != -1) {
    14. if (b != 0 && b > 16 && b != 255 && b != 23 && b != 24) {
    15. str.append((char) b);
    16. }
    17. }
    18.  
    19. String[] data = str.toString().split(String.valueOf(ChatColor.COLOR_CHAR));
    20. String serverMotd = data[0];
    21.  
    22. sock.close();
    23.  
    24. return String.format(serverMotd);
    25. } catch (ConnectException e) {
    26. return ChatColor.RED + "Offline";
    27. } catch (UnknownHostException e) {
    28. return ChatColor.RED + "Offline";
    29. } catch (IOException e) {
    30. return ChatColor.RED + "Offline";
    31. }
    32. }


    That gets the motd of the server fine but when i use this on the 2nd server:

    Code:java
    1. public void onServerPing(ServerListPingEvent event) {
    2. event.setMotd("Waiting...");
    3. }


    it still returns the motd thats in the server.properties and not the new one i set as "Waiting..."!

    If anyone knows what i'm doing wrong please tell me, also my servers are linked with Bungee Cord so if there is another way of getting the motd of a server i could use that. I dont really want to use MySQL if i can help it so ill try anything else first.

    Thanks in advance.

    - CaptainCoder
     
  2. Offline

    simolus3

    CaptainCoder Weird. Your code of the second one looks correct. The only reason I can think of is that you might have forgotten to add an @EventHandler or register your events... I mean, if you have two servers and one of them pings the other one correctly, the error must be at the second one. To check if your first code really works, you might want to check out some other server-IP' s and see what they return...
     
  3. Offline

    xAstraah

    CaptainCoder, @EventHandler and double check you have registered you're events.
     
Thread Status:
Not open for further replies.

Share This Page