forked from LogBlock/LogBlock
Use GSON in UUIDFetcher
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
package de.diddiz.util;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
@ -18,18 +19,18 @@ import java.util.UUID;
|
||||
public class UUIDFetcher {
|
||||
|
||||
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
||||
private static final JSONParser jsonParser = new JSONParser();
|
||||
private static final Gson gson = new GsonBuilder().setLenient().create();
|
||||
|
||||
public static Map<String, UUID> getUUIDs(List<String> names) throws Exception {
|
||||
Map<String, UUID> uuidMap = new HashMap<>();
|
||||
HttpURLConnection connection = createConnection();
|
||||
String body = JSONArray.toJSONString(names);
|
||||
String body = gson.toJson(names);
|
||||
writeBody(connection, body);
|
||||
JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
||||
for (Object profile : array) {
|
||||
JSONObject jsonProfile = (JSONObject) profile;
|
||||
String id = (String) jsonProfile.get("id");
|
||||
String name = (String) jsonProfile.get("name");
|
||||
JsonArray array = gson.fromJson(new InputStreamReader(connection.getInputStream()), JsonArray.class);
|
||||
for (JsonElement profile : array) {
|
||||
JsonObject jsonProfile = (JsonObject) profile;
|
||||
String id = jsonProfile.get("id").getAsString();
|
||||
String name = jsonProfile.get("name").getAsString();
|
||||
UUID uuid = getUUID(id);
|
||||
uuidMap.put(name, uuid);
|
||||
}
|
||||
|
Reference in New Issue
Block a user