11package cn .xiaopangxie732 .mojang_api ;
22
3- import java .util .HashMap ;
4- import java .util .Properties ;
5- import com .google .gson .Gson ;
6-
73import cn .xiaopangxie732 .mojang_api .util .Net ;
4+ import com .google .gson .JsonArray ;
5+ import com .google .gson .JsonObject ;
6+ import com .google .gson .JsonParser ;
7+
8+ import java .util .Properties ;
89
910/**
10- * Used to check the Mojang's servers status.
11+ * Used to check the Mojang servers status.
1112 * @author XiaoPangxie732
1213 */
1314public class Status {
@@ -30,6 +31,7 @@ public enum StatusServer {
3031 /**
3132 * Let enum to string.<br>
3233 * @return The lower case of enum name.
34+ * @since 0.0.1
3335 * @author XiaoPangxie732
3436 */
3537 @ Override
@@ -52,6 +54,7 @@ public enum StatusType {
5254 /**
5355 * Let enum to string.
5456 * @return The lower case of enum name.
57+ * @since 0.0.1
5558 * @author XiaoPangxie732
5659 */
5760 @ Override
@@ -62,10 +65,10 @@ public String toString() {
6265
6366 private final String url = "https://status.mojang.com/check" ;
6467 private String response ;
65- private Gson json = new Gson ();
6668
6769 /**
6870 * Construct a <code>Status</code> class.
71+ * @since 0.0.1
6972 */
7073 public Status () {
7174 response = Net .getConnection (url );
@@ -81,19 +84,21 @@ public Status() {
8184 */
8285 public StatusType getStatus (StatusServer server ) throws NullPointerException {
8386 if (server == null ) throw new NullPointerException ("The server is null" );
84- Properties [] parr = json .fromJson (response , Properties [].class );
85- HashMap <String , String > result = new HashMap <>();
86- for (Properties p : parr ) {
87- result .put ((String )p .keySet ().toArray ()[0 ], p .getProperty ((String )p .keySet ().toArray ()[0 ]));
87+ JsonArray array = new JsonParser ().parse (response ).getAsJsonArray ();
88+ Properties result = new Properties ();
89+ for (int var = 0 ;var < array .size (); ++var ) {
90+ JsonObject object = array .get (var ).getAsJsonObject ();
91+ Object [] key = object .keySet ().toArray ();
92+ result .setProperty ((String )key [0 ], object .get (key [0 ].toString ()).getAsString ());
8893 }
89- String value = result .get (server .toString ());
94+ String value = result .getProperty (server .toString ());
9095 switch (value ) {
91- case "green" :
92- return StatusType .GREEN ;
93- case "yellow" :
94- return StatusType .YELLOW ;
95- case "red" :
96- return StatusType .RED ;
96+ case "green" :
97+ return StatusType .GREEN ;
98+ case "yellow" :
99+ return StatusType .YELLOW ;
100+ case "red" :
101+ return StatusType .RED ;
97102 }
98103 return StatusType .ERROR_TO_CONNECT ;
99104 }
0 commit comments