Ir para conteúdo
  • 0

[Bukkit Code][Duvida] BungeeCord/Pingner


Solitario

Pergunta

Bom gostaria de saber como posso pegar os players e max players de um servidor ... tentei com varios code só que todos deram no mesmo resultado e não funcional ...

Usei tipo socket:

    public static String connect(){
    	try {
    		Socket sock = new Socket(ip, porta);
    		 
    		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);
    		}
    		}
    		 
    		String[] data = str.toString().split("§");
    		int onlinePlayers = Integer.parseInt(data[1]);
    		int maxPlayers = Integer.parseInt(data[2]);
    		 
    		return onlinePlayers + "/" + maxPlayers;
    		 
    		} catch (UnknownHostException e) {
    		e.printStackTrace();
    		} catch (IOException e) {
    		e.printStackTrace();
    		}
		return "§cOffline";
    }

@EDIT:

Erro:

https://hastebin.com/irumayanat.vbs

Editado por Solitario
Link para o comentário
Compartilhar em outros sites

4 respostass a esta questão

Posts Recomendados

Resolvido ...

 

Quem quiser a api:

	   public static String getPlayers(String ip, String port) {
		   try (Socket sock = new Socket(ip, Integer.parseInt(port));
				   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) str.append((char) b);
			   }
				 
			   return str.toString().split("§")[10] + "/" + str.toString().split("§")[11];
		   } catch (IOException ex) {
			   return "§cOffline";
		   }  
	    }

OBS: ele tem um serio problema com algums servers (Creio que sejá devido ao motd só ir mudando o [10] e [11])

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.
×
×
  • Criar Novo...