private String fetchUUID(final String player) {
try {
HttpURLConnection connection = (HttpURLConnection) new URL(
"
https://api.mojang.com/profiles/minecraft").
openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
try (DataOutputStream out = new DataOutputStream(connection.
getOutputStream())) {
out.write(("[\"" + player + "\"]").getBytes(Charsets.UTF_8));
out.flush();
}
BufferedReader reader = new BufferedReader(new InputStreamReader(
connection.getInputStream(), Charsets.UTF_8));
Profile[] profiles = gson.fromJson(reader, Profile[].class);
if (profiles != null && profiles.length >= 1) {
return profiles[0].id;
}
return null;