2014-04-20 05:12:28 +00:00
|
|
|
/**
|
|
|
|
* Copyright © 2013 tuxed <write@imaginarycode.com>
|
|
|
|
* This work is free. You can redistribute it and/or modify it under the
|
|
|
|
* terms of the Do What The Fuck You Want To Public License, Version 2,
|
|
|
|
* as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
|
|
|
|
*/
|
|
|
|
package com.imaginarycode.minecraft.redisbungee.util;
|
|
|
|
|
2015-01-09 14:45:45 +00:00
|
|
|
import com.google.gson.JsonArray;
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
import com.google.gson.JsonParser;
|
2014-04-20 05:12:28 +00:00
|
|
|
|
2015-01-09 14:44:03 +00:00
|
|
|
import java.io.IOException;
|
2014-04-20 05:12:28 +00:00
|
|
|
import java.net.URL;
|
2015-01-09 14:44:03 +00:00
|
|
|
import java.net.URLConnection;
|
2015-01-09 14:45:45 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Scanner;
|
|
|
|
import java.util.UUID;
|
2014-04-20 05:12:28 +00:00
|
|
|
|
2015-01-09 14:44:03 +00:00
|
|
|
public class NameFetcher {
|
2015-01-09 14:45:45 +00:00
|
|
|
private static JsonParser parser = new JsonParser();
|
|
|
|
|
|
|
|
public static List<String> nameHistoryFromUuid(UUID uuid) {
|
|
|
|
URLConnection connection;
|
|
|
|
try {
|
|
|
|
connection = new URL("https://api.mojang.com/user/profiles/"
|
|
|
|
+ uuid.toString().replace("-", "").toLowerCase() + "/names"
|
|
|
|
).openConnection();
|
|
|
|
String text = new Scanner(connection.getInputStream()).useDelimiter("\\Z").next();
|
|
|
|
JsonArray list = (JsonArray) parser.parse(text);
|
|
|
|
List<String> names = new ArrayList<>();
|
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
names.add(((JsonObject) list.get(i)).get("name").getAsString());
|
|
|
|
}
|
|
|
|
return names;
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return null;
|
2014-04-20 05:12:28 +00:00
|
|
|
}
|
|
|
|
}
|