Add adminchat

This commit is contained in:
2022-02-24 21:56:28 -06:00
parent b37cd31e98
commit b6f4ddbb4c
5 changed files with 85 additions and 19 deletions

View File

@ -195,33 +195,37 @@ public class PlexUtils extends PlexBase
Bukkit.broadcast(component);
}
public static Object simpleGET(String url) throws IOException, ParseException
public static Object simpleGET(String url)
{
URL u = new URL(url);
HttpURLConnection connection = (HttpURLConnection)u.openConnection();
connection.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
StringBuilder content = new StringBuilder();
while ((line = in.readLine()) != null)
try
{
content.append(line);
URL u = new URL(url);
HttpURLConnection connection = (HttpURLConnection)u.openConnection();
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;
}
in.close();
connection.disconnect();
return new JSONParser().parse(content.toString());
}
public static UUID getFromName(String name)
{
JSONObject profile;
try
profile = (JSONObject)simpleGET("https://api.ashcon.app/mojang/v2/user/" + name);
if (profile == null)
{
profile = (JSONObject)PlexUtils.simpleGET("https://api.ashcon.app/mojang/v2/user/" + name);
}
catch (IOException | ParseException e)
{
e.printStackTrace();
PlexLog.error("Profile from Ashcon API returned null!");
return null;
}
String uuidString = (String)profile.get("uuid");