mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2025-04-20 01:27:07 +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 com.squareup.okhttp.ResponseBody;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class NameFetcher {
|
public class NameFetcher {
|
||||||
private static OkHttpClient httpClient;
|
private static OkHttpClient httpClient;
|
||||||
private static final Gson gson = new Gson();
|
private static final Gson gson = new Gson();
|
||||||
|
|
||||||
public static void setHttpClient(OkHttpClient httpClient) {
|
public static void setHttpClient(OkHttpClient httpClient) {
|
||||||
NameFetcher.httpClient = httpClient;
|
NameFetcher.httpClient = httpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getName(UUID uuid) throws IOException {
|
public static List<String> nameHistoryFromUuid(UUID uuid) throws IOException {
|
||||||
String url = "https://playerdb.co/api/player/minecraft/" + uuid.toString();
|
String name = getName(uuid);
|
||||||
Request request = new Request.Builder()
|
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")
|
.addHeader("User-Agent", "RedisBungee-ProxioDev")
|
||||||
.url(url)
|
.url(url)
|
||||||
.get()
|
.get()
|
||||||
.build();
|
.build();
|
||||||
ResponseBody body = httpClient.newCall(request).execute().body();
|
ResponseBody body = httpClient.newCall(request).execute().body();
|
||||||
String response = body.string();
|
String response = body.string();
|
||||||
body.close();
|
body.close();
|
||||||
|
|
||||||
JsonObject json = gson.fromJson(response, JsonObject.class);
|
JsonObject json = gson.fromJson(response, JsonObject.class);
|
||||||
if (!json.has("success") || !json.get("success").getAsBoolean()) return null;
|
if (!json.has("success") || !json.get("success").getAsBoolean()) return null;
|
||||||
@ -47,5 +55,5 @@ public class NameFetcher {
|
|||||||
if (!player.has("username")) return null;
|
if (!player.has("username")) return null;
|
||||||
|
|
||||||
return player.get("username").getAsString();
|
return player.get("username").getAsString();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user