mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2026-04-08 16:10:26 +00:00
Add a test class
This commit is contained in:
@@ -11,6 +11,7 @@ import com.google.common.collect.*;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.gson.Gson;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.util.NameFetcher;
|
||||
import com.imaginarycode.minecraft.redisbungee.util.UUIDTranslator;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import lombok.Getter;
|
||||
@@ -432,6 +433,7 @@ public final class RedisBungee extends Plugin {
|
||||
public Void call() throws Exception {
|
||||
service = Executors.newFixedThreadPool(16);
|
||||
httpClient = new OkHttpClient();
|
||||
NameFetcher.setHttpClient(httpClient);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -8,9 +8,11 @@ package com.imaginarycode.minecraft.redisbungee.util;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.Request;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
@@ -20,10 +22,13 @@ import java.util.UUID;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class NameFetcher {
|
||||
@Setter
|
||||
private static OkHttpClient httpClient;
|
||||
|
||||
public static List<String> nameHistoryFromUuid(UUID uuid) throws IOException {
|
||||
String url = "https://api.mojang.com/user/profiles/" + uuid.toString().replace("-", "") + "/names";
|
||||
Request request = new Request.Builder().url(url).get().build();
|
||||
String response = RedisBungee.getHttpClient().newCall(request).execute().body().string();
|
||||
String response = httpClient.newCall(request).execute().body().string();
|
||||
|
||||
Type listType = new TypeToken<List<Name>>() {}.getType();
|
||||
List<Name> names = RedisBungee.getGson().fromJson(response, listType);
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/* Credits to evilmidget38 for this class. I modified it to use Gson. */
|
||||
class UUIDFetcher implements Callable<Map<String, UUID>> {
|
||||
public class UUIDFetcher implements Callable<Map<String, UUID>> {
|
||||
private static final double PROFILES_PER_REQUEST = 100;
|
||||
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
||||
private static final MediaType JSON = MediaType.parse("application/json");
|
||||
|
||||
Reference in New Issue
Block a user