/** * Returns a map of Mojang-defined URLs (such as session.minecraft.net) to * a boolean of whether they are currently working or not. *

* If an error occurs, null is returned. * * @return map as specified above */ public Map getMcStatus() { URL checkUrl; try { checkUrl = new URL("http://status.mojang.com/check"); } catch (MalformedURLException impossible) { return null; } InputStreamReader read = null; HashMap ret = new HashMap(); try { Object content = new JSONParser().parse(read = new InputStreamReader(checkUrl.openStream())); read.close(); if (!(content instanceof JSONArray)) { // Bad / old format return null; } JSONArray arr = (JSONArray) content; for (Object obj : arr) { if (obj instanceof JSONObject) { JSONObject jobj = (JSONObject) obj; Map.Entry entry = (Map.Entry) (jobj.entrySet()).iterator().next(); Object key = entry.getKey(); Object value = entry.getValue(); String site = (String) key; boolean val = ((String) value).equalsIgnoreCase("green"); ret.put(site, val); } } return ret; } catch (ClassCastException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } finally { tryClose(read); } return null; } private void tryClose(Closeable c) { if (c == null) return; try { c.close(); } catch (IOException e) { e.printStackTrace(); } }