From 09cba965d3c7bbfb831fdf222f553b628117ff42 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 23 Apr 2019 02:12:22 -0700 Subject: [PATCH] Switch to GSON since mojang lib does not exist in 1.14 --- .../gmail/nossr50/util/uuid/UUIDFetcher.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/util/uuid/UUIDFetcher.java b/src/main/java/com/gmail/nossr50/util/uuid/UUIDFetcher.java index 90bef4122..7bb023707 100644 --- a/src/main/java/com/gmail/nossr50/util/uuid/UUIDFetcher.java +++ b/src/main/java/com/gmail/nossr50/util/uuid/UUIDFetcher.java @@ -1,11 +1,10 @@ package com.gmail.nossr50.util.uuid; import com.google.common.collect.ImmutableList; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; -import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; @@ -17,7 +16,6 @@ public class UUIDFetcher implements Callable> { private static final int PROFILES_PER_REQUEST = 50; private static final long RATE_LIMIT = 100L; private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft"; - private final JSONParser jsonParser = new JSONParser(); private final List names; private final boolean rateLimiting; @@ -35,13 +33,22 @@ public class UUIDFetcher implements Callable> { int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); for (int i = 0; i < requests; i++) { HttpURLConnection connection = createConnection(); - String body = JSONArray.toJSONString(names.subList(i * PROFILES_PER_REQUEST, Math.min((i + 1) * PROFILES_PER_REQUEST, names.size()))); + + List nameSubList = names.subList(i * PROFILES_PER_REQUEST, Math.min((i + 1) * PROFILES_PER_REQUEST, names.size())); + JsonArray array = new JsonArray(); + + for(String name : nameSubList) + { + JsonPrimitive element = new JsonPrimitive(name); + array.add(element); + } + + String body = array.getAsString(); 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"); + JsonObject jsonProfile = (JsonObject) profile; + String id = jsonProfile.get("id").getAsString(); + String name = jsonProfile.get("name").getAsString(); UUID uuid = UUIDFetcher.getUUID(id); uuidMap.put(name, uuid); }