2022-04-19 20:19:55 +00:00
|
|
|
package dev.plex.util;
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.UUID;
|
|
|
|
import org.json.simple.JSONObject;
|
|
|
|
import org.json.simple.parser.JSONParser;
|
|
|
|
import org.json.simple.parser.ParseException;
|
|
|
|
|
|
|
|
public class WebUtils
|
|
|
|
{
|
|
|
|
public static Object simpleGET(String url)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
URL u = new URL(url);
|
2022-08-02 12:08:52 +00:00
|
|
|
HttpURLConnection connection = (HttpURLConnection)u.openConnection();
|
2022-04-19 20:19:55 +00:00
|
|
|
connection.setRequestMethod("GET");
|
|
|
|
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
|
|
String line;
|
|
|
|
StringBuilder content = new StringBuilder();
|
|
|
|
while ((line = in.readLine()) != null)
|
|
|
|
{
|
|
|
|
content.append(line);
|
|
|
|
}
|
|
|
|
in.close();
|
|
|
|
connection.disconnect();
|
|
|
|
return new JSONParser().parse(content.toString());
|
|
|
|
}
|
|
|
|
catch (IOException | ParseException ex)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static UUID getFromName(String name)
|
|
|
|
{
|
|
|
|
JSONObject profile;
|
2022-08-02 12:08:52 +00:00
|
|
|
profile = (JSONObject)simpleGET("https://api.ashcon.app/mojang/v2/user/" + name);
|
2022-04-19 20:19:55 +00:00
|
|
|
if (profile == null)
|
|
|
|
{
|
|
|
|
PlexLog.error("Profile from Ashcon API returned null!");
|
|
|
|
return null;
|
|
|
|
}
|
2022-08-02 12:08:52 +00:00
|
|
|
String uuidString = (String)profile.get("uuid");
|
2022-04-19 20:19:55 +00:00
|
|
|
return UUID.fromString(uuidString);
|
|
|
|
}
|
|
|
|
}
|