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?
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(); }
Okay, it works. 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?
Also, while it is working for you. I just found this (I remembered .getServer() exists): Bukkit.getServer().getMotd(); How are you setting servermotd?