mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-23 04:28:01 +00:00
Add a test class
This commit is contained in:
parent
b684064c92
commit
a80c3b51e1
6
pom.xml
6
pom.xml
@ -163,5 +163,11 @@
|
||||
<version>2.2.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -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");
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.test;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.util.NameFetcher;
|
||||
import com.imaginarycode.minecraft.redisbungee.util.UUIDFetcher;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class UUIDNameTest {
|
||||
@Test
|
||||
public void testUuidToName() throws IOException {
|
||||
OkHttpClient httpClient = new OkHttpClient();
|
||||
String uuid = "68ec43f7234b41b48764dfb38b9ffe8c";
|
||||
NameFetcher.setHttpClient(httpClient);
|
||||
List<String> names = NameFetcher.nameHistoryFromUuid(UUIDFetcher.getUUID(uuid));
|
||||
String currentName = names.get(names.size() - 1);
|
||||
System.out.println("Current name for UUID " + uuid + " is " + currentName);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user