From 161eb5d136823d1528ec4a37412f2c2876c88895 Mon Sep 17 00:00:00 2001 From: Daniel Voort Date: Mon, 17 Jul 2023 23:48:41 +0200 Subject: [PATCH] Add NameFetcher#nameHistoryFromUuid for backward-compatibility --- .../api/util/uuid/NameFetcher.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/util/uuid/NameFetcher.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/util/uuid/NameFetcher.java index 4cf0ccd..69eb689 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/util/uuid/NameFetcher.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/util/uuid/NameFetcher.java @@ -17,26 +17,34 @@ import com.squareup.okhttp.Request; import com.squareup.okhttp.ResponseBody; import java.io.IOException; +import java.util.Collections; +import java.util.List; import java.util.UUID; public class NameFetcher { - private static OkHttpClient httpClient; - private static final Gson gson = new Gson(); + private static OkHttpClient httpClient; + private static final Gson gson = new Gson(); - public static void setHttpClient(OkHttpClient httpClient) { - NameFetcher.httpClient = httpClient; - } + public static void setHttpClient(OkHttpClient httpClient) { + NameFetcher.httpClient = httpClient; + } - public static String getName(UUID uuid) throws IOException { - String url = "https://playerdb.co/api/player/minecraft/" + uuid.toString(); - Request request = new Request.Builder() + public static List nameHistoryFromUuid(UUID uuid) throws IOException { + String name = getName(uuid); + if (name == null) return Collections.emptyList(); + return Collections.singletonList(name); + } + + public static String getName(UUID uuid) throws IOException { + String url = "https://playerdb.co/api/player/minecraft/" + uuid.toString(); + Request request = new Request.Builder() .addHeader("User-Agent", "RedisBungee-ProxioDev") .url(url) .get() .build(); - ResponseBody body = httpClient.newCall(request).execute().body(); - String response = body.string(); - body.close(); + ResponseBody body = httpClient.newCall(request).execute().body(); + String response = body.string(); + body.close(); JsonObject json = gson.fromJson(response, JsonObject.class); if (!json.has("success") || !json.get("success").getAsBoolean()) return null; @@ -47,5 +55,5 @@ public class NameFetcher { if (!player.has("username")) return null; return player.get("username").getAsString(); - } + } } \ No newline at end of file