2021-06-26 19:08:15 -07:00
|
|
|
package net.nuggetmc.ai.utils;
|
|
|
|
|
|
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
|
import com.google.gson.JsonParser;
|
|
|
|
|
|
2021-06-28 03:14:07 -05:00
|
|
|
import java.io.IOException;
|
2021-06-26 19:08:15 -07:00
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
|
|
|
|
|
public class MojangAPI {
|
|
|
|
|
|
2021-06-28 03:14:07 -05:00
|
|
|
// Eventually create some sort of cache that stores the skin data so it doesn't have to keep pulling from the API
|
|
|
|
|
// CATCHING NULLPOINTEREXCEPTION BAD!!!! eventually fix from the getAsJsonObject thingy
|
2021-06-26 19:08:15 -07:00
|
|
|
public static String[] getSkin(String name) {
|
|
|
|
|
try {
|
|
|
|
|
String uuid = new JsonParser().parse(new InputStreamReader(new URL("https://api.mojang.com/users/profiles/minecraft/" + name)
|
|
|
|
|
.openStream())).getAsJsonObject().get("id").getAsString();
|
|
|
|
|
JsonObject property = new JsonParser()
|
|
|
|
|
.parse(new InputStreamReader(new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false")
|
|
|
|
|
.openStream())).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject();
|
|
|
|
|
return new String[] {property.get("value").getAsString(), property.get("signature").getAsString()};
|
2021-06-28 03:14:07 -05:00
|
|
|
} catch (IOException | NullPointerException e) {
|
2021-06-26 19:08:15 -07:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|