mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2025-04-18 16:47:06 +00:00
Add NameFetcher#nameHistoryFromUuid for backward-compatibility
This commit is contained in:
parent
f598f5bf2d
commit
161eb5d136
@ -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<String> 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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user