mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2025-04-20 01:27:07 +00:00
Revert "Revert to old method as the new method has changed"
This reverts commit 16ce4eb696
.
This commit is contained in:
parent
16ce4eb696
commit
6511e2154f
@ -6,46 +6,21 @@
|
|||||||
*/
|
*/
|
||||||
package com.imaginarycode.minecraft.redisbungee.util;
|
package com.imaginarycode.minecraft.redisbungee.util;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
|
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
|
||||||
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.lang.reflect.Type;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
import java.net.URLConnection;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
|
|
||||||
/* Credits to evilmidget38 for this class. I modified it to use Gson. */
|
public class NameFetcher {
|
||||||
class NameFetcher implements Callable<Map<UUID, String>> {
|
public static List<String> nameHistoryFromUuid(UUID uuid) throws IOException {
|
||||||
private static final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
URLConnection connection = new URL("https://api.mojang.com/user/profiles/" + uuid.toString().replace("-", "").toLowerCase() + "/names").openConnection();
|
||||||
private final List<UUID> uuids;
|
String text = new String(ByteStreams.toByteArray(connection.getInputStream()));
|
||||||
|
Type listType = new TypeToken<List<String>>() {}.getType();
|
||||||
public NameFetcher(List<UUID> uuids) {
|
return RedisBungee.getGson().fromJson(text, listType);
|
||||||
this.uuids = ImmutableList.copyOf(uuids);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<UUID, String> call() throws Exception {
|
|
||||||
Map<UUID, String> uuidStringMap = new HashMap<>();
|
|
||||||
for (UUID uuid : uuids) {
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) new URL(PROFILE_URL + uuid.toString().replace("-", "")).openConnection();
|
|
||||||
Map<String, String> response = RedisBungee.getGson().fromJson(new InputStreamReader(connection.getInputStream()), new TypeToken<Map<String, String>>() {
|
|
||||||
}.getType());
|
|
||||||
String name = response.get("name");
|
|
||||||
if (name == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String cause = response.get("cause");
|
|
||||||
String errorMessage = response.get("errorMessage");
|
|
||||||
if (cause != null && cause.length() > 0) {
|
|
||||||
throw new IllegalStateException(errorMessage);
|
|
||||||
}
|
|
||||||
uuidStringMap.put(uuid, name);
|
|
||||||
}
|
|
||||||
return uuidStringMap;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user