/**
 * Copyright © 2013 tuxed <write@imaginarycode.com>
 * This work is free. You can redistribute it and/or modify it under the
 * terms of the Do What The Fuck You Want To Public License, Version 2,
 * as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
 */
package com.imaginarycode.minecraft.redisbungee.util;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.UUID;

public class NameFetcher {
    private static JsonParser parser = new JsonParser();

    public static List<String> nameHistoryFromUuid(UUID uuid) {
        URLConnection connection;
        try {
            connection = new URL("https://api.mojang.com/user/profiles/"
                    + uuid.toString().replace("-", "").toLowerCase() + "/names"
            ).openConnection();
            String text = new Scanner(connection.getInputStream()).useDelimiter("\\Z").next();
            JsonArray list = (JsonArray) parser.parse(text);
            List<String> names = new ArrayList<>();
            for (int i = 0; i < list.size(); i++) {
                names.add(((JsonObject) list.get(i)).get("name").getAsString());
            }
            return names;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
@@ -351,22 +351,29 @@
 gle.
-gson.JsonArray
+common.io.ByteStreams
 ;%0Aim
@@ -397,321 +397,437 @@
 son.
-JsonObject;%0Aimport com.google.gson.JsonParser;%0A%0Aimport java.io.IOException;%0Aimport java.net.URL;%0Aimport java.net.URLConnection;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.Scanner;%0Aimport java.util.UUID;%0A%0Apublic class NameFetcher %7B%0A    private static JsonParser parser = new JsonParser();%0A
+reflect.TypeToken;%0Aimport com.imaginarycode.minecraft.redisbungee.RedisBungee;%0Aimport lombok.AccessLevel;%0Aimport lombok.NoArgsConstructor;%0A%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.lang.reflect.Type;%0Aimport java.net.URL;%0Aimport java.net.URLConnection;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.UUID;%0A%0A@NoArgsConstructor(access = AccessLevel.PRIVATE)%0Apublic class NameFetcher %7B
 %0A   
@@ -884,16 +884,35 @@
 ID uuid)
+ throws IOException
  %7B%0A     
@@ -932,46 +932,8 @@
 ion 
-connection;%0A        try %7B%0A            
 conn
@@ -992,28 +992,8 @@
 es/%22
-%0A                   
  + u
@@ -1048,29 +1048,16 @@
 %22/names%22
-%0A            
 ).openCo
@@ -1068,26 +1068,25 @@
 tion();%0A
-  
+%0A
         
   String
@@ -1077,18 +1077,16 @@
         
-  
 String t
@@ -1092,77 +1092,129 @@
 text
- = new Scanner(connection.getInputStream()).useDelimiter(%22%5C%5CZ%22).next(
+;%0A%0A        try (InputStream is = connection.getInputStream()) %7B%0A            text = new String(ByteStreams.toByteArray(is)
 );%0A 
@@ -1224,65 +1224,153 @@
     
+%7D%0A%0A
     
-JsonArray list = (JsonArray) parser.parse(text);%0A    
+    Type listType = new TypeToken%3CList%3CName%3E%3E() %7B%7D.getType();%0A        List%3CName%3E names = RedisBungee.getGson().fromJson(text, listType);%0A%0A
     
@@ -1386,17 +1386,22 @@
 String%3E 
-n
+humanN
 ames = n
@@ -1430,48 +1430,30 @@
     
-    
 for (
-int i = 0; i %3C list.size(); i++
+Name name : names
 ) %7B%0A
@@ -1468,13 +1468,14 @@
     
-    n
+humanN
 ames
@@ -1483,67 +1483,20 @@
 add(
-((JsonObject) list.get(i)).get(%22name%22).getAsString());%0A    
+name.name);%0A
     
@@ -1509,28 +1509,29 @@
         
-    
 return 
-n
+humanN
 ames;%0A  
@@ -1536,50 +1536,50 @@
     
+%7D%0A%0A
     
-%7D catch (IOException e) %7B%0A    
+public static class Name %7B%0A
         
 e.pr
@@ -1578,58 +1578,27 @@
     
-e.
 pri
-ntStackTrace();%0A        %7D%0A        return null
+vate String name
 ;%0A  

Make NameFetcher less hazardous to ones health.