Advertisement
TriiNoxYs

Get Server Infos (Java)

Jul 8th, 2015
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. public void update(){
  2.         try{
  3.             Socket socket = new Socket();
  4.             socket.connect(new InetSocketAddress(ip, port), 1 * 1000);
  5.             DataOutputStream out = new DataOutputStream(socket.getOutputStream());
  6.             DataInputStream in = new DataInputStream(socket.getInputStream());
  7.             out.write(0xFE);
  8.             StringBuilder str = new StringBuilder();
  9.             int b;
  10.             while((b = in.read()) != -1){
  11.                 if(b != 0 && b > 16 && b != 255 && b != 23 && b != 24){
  12.                     str.append((char) b);
  13.                 }
  14.             }
  15.             String[] data = str.toString().split("§");
  16.             int onlinePlayers = Integer.valueOf(data[1]);
  17.             int maxPlayers = Integer.valueOf(data[2]);
  18.             String motd = data[0];
  19.             sign.setLine(0, "§aMini-Jeu");
  20.             sign.setLine(1, onlinePlayers + "/" + maxPlayers);
  21.             sign.setLine(2, ip);
  22.             sign.setLine(3, motd);
  23.             socket.close();
  24.         }catch(Exception e){
  25.             error = e.getLocalizedMessage();
  26.            
  27.             sign.setLine(0, "§4Mini-Jeu");
  28.             sign.setLine(1, null);
  29.             sign.setLine(2, ChatColor.DARK_RED + "Serveur fermé.");
  30.             sign.setLine(3, null);
  31.         }
  32.         sign.update();
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement