mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 07:06:45 +01:00
Switch to GSON since mojang lib does not exist in 1.14
This commit is contained in:
parent
d862f7f779
commit
09cba965d3
@ -1,11 +1,10 @@
|
|||||||
package com.gmail.nossr50.util.uuid;
|
package com.gmail.nossr50.util.uuid;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import org.json.simple.JSONArray;
|
import com.google.gson.JsonArray;
|
||||||
import org.json.simple.JSONObject;
|
import com.google.gson.JsonObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import com.google.gson.JsonPrimitive;
|
||||||
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -17,7 +16,6 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> {
|
|||||||
private static final int PROFILES_PER_REQUEST = 50;
|
private static final int PROFILES_PER_REQUEST = 50;
|
||||||
private static final long RATE_LIMIT = 100L;
|
private static final long RATE_LIMIT = 100L;
|
||||||
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
||||||
private final JSONParser jsonParser = new JSONParser();
|
|
||||||
private final List<String> names;
|
private final List<String> names;
|
||||||
private final boolean rateLimiting;
|
private final boolean rateLimiting;
|
||||||
|
|
||||||
@ -35,13 +33,22 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> {
|
|||||||
int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
|
int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
|
||||||
for (int i = 0; i < requests; i++) {
|
for (int i = 0; i < requests; i++) {
|
||||||
HttpURLConnection connection = createConnection();
|
HttpURLConnection connection = createConnection();
|
||||||
String body = JSONArray.toJSONString(names.subList(i * PROFILES_PER_REQUEST, Math.min((i + 1) * PROFILES_PER_REQUEST, names.size())));
|
|
||||||
|
List<String> 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);
|
writeBody(connection, body);
|
||||||
JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
|
||||||
for (Object profile : array) {
|
for (Object profile : array) {
|
||||||
JSONObject jsonProfile = (JSONObject) profile;
|
JsonObject jsonProfile = (JsonObject) profile;
|
||||||
String id = (String) jsonProfile.get("id");
|
String id = jsonProfile.get("id").getAsString();
|
||||||
String name = (String) jsonProfile.get("name");
|
String name = jsonProfile.get("name").getAsString();
|
||||||
UUID uuid = UUIDFetcher.getUUID(id);
|
UUID uuid = UUIDFetcher.getUUID(id);
|
||||||
uuidMap.put(name, uuid);
|
uuidMap.put(name, uuid);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user