Skip to content

Instantly share code, notes, and snippets.

@ScruffyRules
Created April 8, 2014 13:41
Show Gist options
  • Save ScruffyRules/10125846 to your computer and use it in GitHub Desktop.
Save ScruffyRules/10125846 to your computer and use it in GitHub Desktop.
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