Core/src/de/joethei/core/api/MojangService.java

120 lines
3.0 KiB
Java

package de.joethei.core.api;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
public class MojangService
{
private static JSONParser parser = new JSONParser();
public static ServiceStatus getStatus(MinecraftServer service)
{
String status = null;
try
{
URL url = new URL("http://status.mojang.com/check?service=" + service.getURL());
BufferedReader input = new BufferedReader(new InputStreamReader(url.openStream()));
Object object = parser.parse(input);
JSONObject jsonObject = (JSONObject)object;
status = (String)jsonObject.get(service.getURL());
} catch (Exception e) {
return ServiceStatus.UNKNOWN;
}
return status(status);
}
public static ServiceStatus getStatus(MojangServer service) {
String status = null;
try
{
URL url = new URL("http://status.mojang.com/check?service=" + service.getURL());
BufferedReader input = new BufferedReader(new InputStreamReader(url.openStream()));
Object object = parser.parse(input);
JSONObject jsonObject = (JSONObject)object;
status = (String)jsonObject.get(service.getURL());
} catch (Exception e) {
return ServiceStatus.UNKNOWN;
}
return status(status);
}
private static ServiceStatus status(String status)
{
String str;
switch ((str = status.toLowerCase()).hashCode()) { case -734239628:
if (str.equals("yellow")) break; break;
case 112785:
if (str.equals("red"));
case 98619139:
if ((goto 92) && (str.equals("green")))
{
return ServiceStatus.ONLINE;
return ServiceStatus.EXPERIENCE;
return ServiceStatus.OFFLINE;
}
}
return ServiceStatus.UNKNOWN;
}
public static enum MinecraftServer
{
WEBSITE("minecraft.net"),
LOGIN("login.minecraft.net"),
SKIN("skins.minecraft.net"),
SESSION("session.minecraft.net");
private String url;
private MinecraftServer(String url) { this.url = url; }
private String getURL()
{
return this.url;
}
}
public static enum MojangServer
{
ACCOUNT("account.mojang.com"),
AUTH("auth.mojang.com"),
AUTHSERVER("authserver.mojang.com"),
SESSION("sessionserver.mojang.com");
private String url;
private MojangServer(String url) { this.url = url; }
private String getURL()
{
return this.url;
}
}
public static enum ServiceStatus
{
ONLINE("No problems detected!"),
EXPERIENCE("May be experiencing issues"),
OFFLINE("Experiencing problems!"),
UNKNOWN("Couldn't connect to Mojang!");
private String description;
private ServiceStatus(String description) { this.description = description; }
public String getDescription()
{
return this.description;
}
}
}