@@ -58,7 +58,7 @@ public MinecraftServer(String host,int port)throws Exception {
5858 dataInputStream .readByte ();
5959 byte [] b =new byte [512 ];
6060 dataInputStream .read (b );
61- ByteBase bbase =new ByteBase (b );
61+ ByteBase bbase = new ByteBase (b );
6262 byte [] end =new byte []{0 ,0 };
6363 if (new String (bbase .pop (end ),StandardCharsets .UTF_16BE ).equals ("§1" )){
6464 response =new Response ();
@@ -76,13 +76,45 @@ public MinecraftServer(String host,int port)throws Exception {
7676 available =true ;
7777 }
7878 }
79+ if (!available ){//version lower then 1.4
80+
81+ socket =new Socket (host ,port );
82+ dataInputStream =new DataInputStream (socket .getInputStream ());
83+ dataOutputStream =new DataOutputStream (socket .getOutputStream ());
84+
85+ dataOutputStream .write (0xFE );
86+ dataOutputStream .flush ();
87+
88+ if (dataInputStream .readByte ()==-1 ){
89+ dataInputStream .readByte ();
90+ dataInputStream .readByte ();
91+ byte [] b =new byte [512 ];
92+ dataInputStream .read (b );
93+ ByteBase bbase = new ByteBase (b );
94+ byte [] end =new byte []{0 , (byte ) 0xa7 };
95+ byte [] zeroEnd =new byte []{0 , 0 };
96+
97+ response =new Response ();
98+ response .version =new Response .version ();
99+ response .version .name ="<1.4" ;
100+ response .version .protocol =-1 ;
101+
102+ response .description =new Response .description ();
103+ response .description .text =new String (bbase .pop (end ),StandardCharsets .UTF_16BE );
104+
105+ response .players =new Response .players ();
106+ response .players .online =Integer .parseInt (new String (bbase .pop (end ),StandardCharsets .UTF_16BE ));
107+ response .players .max =Integer .parseInt (new String (bbase .pop (zeroEnd ),StandardCharsets .UTF_16BE ));
108+ available =true ;
109+ }
110+ }
79111 }
80112 }
81113 private short len (String l ){
82114 String utf16be =new String (l .getBytes (StandardCharsets .UTF_8 ),StandardCharsets .UTF_16BE );
83115 return (short )utf16be .length ();
84116 }
85- private class ByteBase {
117+ private static class ByteBase {
86118 byte [] arr ;
87119 int index =0 ;
88120 ByteBase (byte [] byteArr ){
@@ -97,6 +129,8 @@ public byte[] pop(byte[] end){
97129 ArrayList <Byte > byteArrayList =new ArrayList <>();
98130 byte [] b =new byte [2 ];
99131 while (true ){
132+ if (index >=arr .length -1 )
133+ break ;
100134 b =pop (2 );
101135 if (b [0 ]==end [0 ]&&b [1 ]==end [1 ]){
102136 break ;
0 commit comments