2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2025-04-20 01:27:07 +00:00

Use PlayerDB.co for names, instead of failing lookups for unknown players

This commit is contained in:
Daniel Voort 2023-07-12 12:49:59 +02:00
parent 7fb9c4689e
commit 60e9e2acbd
4 changed files with 23 additions and 42 deletions

View File

@ -11,50 +11,37 @@
package com.imaginarycode.minecraft.redisbungee.api.util.uuid; package com.imaginarycode.minecraft.redisbungee.api.util.uuid;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.JsonObject;
import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request; 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.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
@Deprecated
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();
@Deprecated
public static void setHttpClient(OkHttpClient httpClient) { public static void setHttpClient(OkHttpClient httpClient) {
throw new UnsupportedOperationException("Due mojang disabled the Names API NameFetcher no longer functions and has been disabled"); NameFetcher.httpClient = httpClient;
// NameFetcher.httpClient = httpClient;
} }
@Deprecated 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();
throw new UnsupportedOperationException("Due mojang disabled the Names API NameFetcher no longer functions and has been disabled"); Request request = new Request.Builder().url(url).get().build();
// String url = "https://api.mojang.com/user/profiles/" + uuid.toString().replace("-", "") + "/names"; ResponseBody body = httpClient.newCall(request).execute().body();
// Request request = new Request.Builder().url(url).get().build(); String response = body.string();
// ResponseBody body = httpClient.newCall(request).execute().body(); body.close();
// String response = body.string();
// body.close();
//
// Type listType = new TypeToken<List<Name>>() {
// }.getType();
// List<Name> names = gson.fromJson(response, listType);
//
// List<String> humanNames = new ArrayList<>();
// for (Name name : names) {
// humanNames.add(name.name);
// }
// return humanNames;
}
@Deprecated JsonObject json = gson.fromJson(response, JsonObject.class);
public static class Name { if (!json.has("success") || !json.get("success").getAsBoolean()) return null;
private String name; if (!json.has("data")) return null;
private long changedToAt; JsonObject data = json.getAsJsonObject("data");
if (!data.has("player")) return null;
JsonObject player = data.getAsJsonObject("player");
if (!player.has("username")) return null;
return player.get("username").getAsString();
} }
} }

View File

@ -12,7 +12,6 @@ package com.imaginarycode.minecraft.redisbungee.api.util.uuid;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin; import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
@ -169,17 +168,12 @@ public final class UUIDTranslator {
if (!expensiveLookups || !plugin.isOnlineMode()) if (!expensiveLookups || !plugin.isOnlineMode())
return null; return null;
// That didn't work. Let's ask Mojang. This call may fail, because Mojang is insane. // That didn't work. Let's ask PlayerDB.
//
// UPDATE: Mojang has removed the API somewhere in september/2022 due privacy issues
// this is expected to fail now, so we will keep logging it until we figure out something or remove name fetching completely
// Name fetching class was deprecated as result
String name; String name;
try { try {
plugin.logFatal("Due Mojang removing the naming API, we were unable to fetch player names."); name = NameFetcher.getName(player);
name = Iterables.getLast(NameFetcher.nameHistoryFromUuid(player));
} catch (Exception e) { } catch (Exception e) {
plugin.logFatal("Unable to fetch name from Mojang for " + player); plugin.logFatal("Unable to fetch name from PlayerDB for " + player);
return null; return null;
} }

View File

@ -223,7 +223,7 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlay
httpClient = new OkHttpClient(); httpClient = new OkHttpClient();
Dispatcher dispatcher = new Dispatcher(getExecutorService()); Dispatcher dispatcher = new Dispatcher(getExecutorService());
httpClient.setDispatcher(dispatcher); httpClient.setDispatcher(dispatcher);
//NameFetcher.setHttpClient(httpClient); NameFetcher.setHttpClient(httpClient);
UUIDFetcher.setHttpClient(httpClient); UUIDFetcher.setHttpClient(httpClient);
InitialUtils.checkRedisVersion(this); InitialUtils.checkRedisVersion(this);
// check if this proxy is recovering from a crash and start heart the beat. // check if this proxy is recovering from a crash and start heart the beat.

View File

@ -110,7 +110,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player>, Con
this.httpClient = new OkHttpClient(); this.httpClient = new OkHttpClient();
Dispatcher dispatcher = new Dispatcher(Executors.newFixedThreadPool(6)); Dispatcher dispatcher = new Dispatcher(Executors.newFixedThreadPool(6));
this.httpClient.setDispatcher(dispatcher); this.httpClient.setDispatcher(dispatcher);
//NameFetcher.setHttpClient(httpClient); NameFetcher.setHttpClient(httpClient);
UUIDFetcher.setHttpClient(httpClient); UUIDFetcher.setHttpClient(httpClient);
} }