[Solved] How do I get a servers motd?

Discussion in 'BungeeCord Plugin Development' started by TimeVisualSales, May 13, 2015.

Thread Status:
Not open for further replies.
  1. Hi there, I was wondering how I would get a server MOTD? I want it so that the MOTD is displayed on a item in a GUI but on the lore. How would I do this?
     
  2. There isn't an API or anything for it unless you use another plugin.
     
    • Agree Agree x 1
  3. Found this, do you think it'll work?
    Code (Text):
    try {
    Socket sock = new Socket("skorcraft.net", 25565);
    DataOutputStream out = new DataOutputStream(sock.getOutputStream());
    DataInputStream in = new DataInputStream(sock.getInputStream());
    out.write(0xFE);
    int b;
    StringBuffer str = new StringBuffer();
    while ((b = in.read()) != -1) {
    if (b != 0 && b > 16 && b != 255 && b != 23 && b != 24) {
    // Not sure what use the two characters are so I omit them
    str.append((char) b);
    System.out.println(b + ":" + ((char) b));
    }
    }
    String[] data = str.toString().split("§");
    String serverMotd = data[0];
    int onlinePlayers = Integer.parseInt(data[1]);
    int maxPlayers = Integer.parseInt(data[2]);
    System.out.println(String.format(
    "MOTD: \"%s\"\nOnline Players: %d/%d", serverMotd,
    onlinePlayers, maxPlayers));
    } catch (UnknownHostException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
     
  4. Have you tried it?
     
  5. I'm using that as well.. I have not tested it, but the guy who made it said it works.
     
  6. I'll go and try it now ;)
     
  7. Okay, it works.
    [​IMG]

    I'm gonna add it to the GUI in a minute but how could I change the item in the GUI? For example if the MOTD was to say 'Lobby' the item in the GUI would be a emerald block and if it the MOTD was to say 'InGame' it would change to a redstone block. How would I be able to do this?
     
  8. if (servermotd.equalIgnoreCase("onLobby") {}
     
  9. Also, while it is working for you. I just found this (I remembered .getServer() exists):
    Bukkit.getServer().getMotd();

    How are you setting servermotd?
     
  10. Ow ok, that was stupid of me to not know. #FACEPALM
     
  11. Ok, just done this and it works :D
    [​IMG]
    The online lore is the MOTD of another server I have.
     
  12. SOLVED
     
    • Like Like x 1
Thread Status:
Not open for further replies.