Skip to content

Commit e57d310

Browse files
Changed getStatus method in Status class
1 parent 474417a commit e57d310

File tree

2 files changed

+43
-17
lines changed

2 files changed

+43
-17
lines changed

mojang-api.iml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
4+
<output url="file://$MODULE_DIR$/target/classes" />
5+
<output-test url="file://$MODULE_DIR$/target/test-classes" />
6+
<content url="file://$MODULE_DIR$">
7+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
9+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
10+
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
11+
<excludeFolder url="file://$MODULE_DIR$/target" />
12+
</content>
13+
<orderEntry type="inheritedJdk" />
14+
<orderEntry type="sourceFolder" forTests="false" />
15+
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.5" level="project" />
16+
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.7" level="project" />
17+
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.11" level="project" />
18+
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
19+
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.11" level="project" />
20+
</component>
21+
</module>

src/main/java/cn/xiaopangxie732/mojang_api/Status.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package cn.xiaopangxie732.mojang_api;
22

3-
import java.util.HashMap;
4-
import java.util.Properties;
5-
import com.google.gson.Gson;
6-
73
import 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
*/
1314
public 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

Comments
 (0)