Created
April 8, 2014 13:41
-
-
Save ScruffyRules/10125846 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.util.Map; | |
import com.google.gson.JsonArray; | |
import com.google.gson.JsonElement; | |
import com.google.gson.JsonParser; | |
public class MinecraftStatus { | |
public static void main(String[] args) throws MalformedURLException, IOException { | |
JsonParser parser = new JsonParser(); | |
InputStream input = new URL("http://status.mojang.com/check").openStream(); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(input)); | |
String status = reader.readLine(); | |
JsonArray json = parser.parse(status).getAsJsonArray(); | |
for (Object obj : json) { | |
Map.Entry<String, JsonElement> entry = parser.parse(obj.toString()).getAsJsonObject().entrySet().iterator().next(); | |
if (entry.getKey().equals("login.minecraft.net")) { | |
if (entry.getValue().getAsString().equals("red")) { | |
System.out.println("Login servers are down!"); | |
} else if (entry.getValue().getAsString().equals("yellow")) { | |
System.out.println("Login servers are slow!"); | |
} | |
} | |
if (entry.getKey().equals("session.minecraft.net")) { | |
if (entry.getValue().getAsString().equals("red")) { | |
System.out.println("Session servers are down!"); | |
} else if (entry.getValue().getAsString().equals("yellow")) { | |
System.out.println("Session servers are slow!"); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment