mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-23 04:28:01 +00:00
Allow RedisBungee to give the console an IOException instead of a unhelpful exception + NPE combo.
This commit is contained in:
parent
3c7c9c616a
commit
5a0509ac48
@ -6,9 +6,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.imaginarycode.minecraft.redisbungee.util;
|
package com.imaginarycode.minecraft.redisbungee.util;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
@ -17,20 +17,10 @@ import java.net.URLConnection;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class NameFetcher {
|
public class NameFetcher {
|
||||||
public static List<String> nameHistoryFromUuid(UUID uuid) {
|
public static List<String> nameHistoryFromUuid(UUID uuid) throws IOException {
|
||||||
URLConnection connection;
|
URLConnection connection = new URL("https://api.mojang.com/user/profiles/" + uuid.toString().replace("-", "").toLowerCase() + "/names").openConnection();
|
||||||
try {
|
String text = new String(ByteStreams.toByteArray(connection.getInputStream()));
|
||||||
connection = new URL("https://api.mojang.com/user/profiles/"
|
Type listType = new TypeToken<List<String>>() {}.getType();
|
||||||
+ uuid.toString().replace("-", "").toLowerCase() + "/names"
|
return RedisBungee.getGson().fromJson(text, listType);
|
||||||
).openConnection();
|
|
||||||
String text = new Scanner(connection.getInputStream()).useDelimiter("\\Z").next();
|
|
||||||
Type listType = new TypeToken<List<String>>() {
|
|
||||||
}.getType();
|
|
||||||
List<String> list = new Gson().fromJson(text, listType);
|
|
||||||
return list;
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user