deprecated NameFetcher api

This commit is contained in:
mohammed jasem alaajel 2022-12-31 07:23:35 +04:00
parent c3888c8f65
commit 1a2459b64e
No known key found for this signature in database
5 changed files with 60 additions and 20 deletions

View File

@ -1,3 +1,13 @@
/*
* Copyright (c) 2013-present RedisBungee contributors
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/
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;
@ -11,32 +21,38 @@ import java.util.ArrayList;
import java.util.List; 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) {
NameFetcher.httpClient = httpClient; throw new UnsupportedOperationException("Due mojang disabled the Names API NameFetcher no longer functions and has been disabled");
// NameFetcher.httpClient = httpClient;
} }
@Deprecated
public static List<String> nameHistoryFromUuid(UUID uuid) throws IOException { public static List<String> nameHistoryFromUuid(UUID uuid) throws IOException {
String url = "https://api.mojang.com/user/profiles/" + uuid.toString().replace("-", "") + "/names"; 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(); // Type listType = new TypeToken<List<Name>>() {
List<Name> names = gson.fromJson(response, listType); // }.getType();
// List<Name> names = gson.fromJson(response, listType);
List<String> humanNames = new ArrayList<>(); //
for (Name name : names) { // List<String> humanNames = new ArrayList<>();
humanNames.add(name.name); // for (Name name : names) {
} // humanNames.add(name.name);
return humanNames; // }
// return humanNames;
} }
@Deprecated
public static class Name { public static class Name {
private String name; private String name;
private long changedToAt; private long changedToAt;

View File

@ -1,3 +1,13 @@
/*
* Copyright (c) 2013-present RedisBungee contributors
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.imaginarycode.minecraft.redisbungee.api.util.uuid; package com.imaginarycode.minecraft.redisbungee.api.util.uuid;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;

View File

@ -1,3 +1,13 @@
/*
* Copyright (c) 2013-present RedisBungee contributors
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.imaginarycode.minecraft.redisbungee.api.util.uuid; package com.imaginarycode.minecraft.redisbungee.api.util.uuid;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
@ -160,10 +170,14 @@ public final class UUIDTranslator {
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 Mojang. This call may fail, because Mojang is insane.
//
// 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 {
List<String> nameHist = NameFetcher.nameHistoryFromUuid(player); plugin.logFatal("Due Mojang removing the naming API, we were unable to fetch player names.");
name = Iterables.getLast(nameHist, null); 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 Mojang for " + player);
return null; return null;

View File

@ -222,7 +222,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

@ -109,7 +109,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);
} }