/**
 * 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.common.collect.ImmutableList;
import com.google.gson.reflect.TypeToken;
import com.imaginarycode.minecraft.redisbungee.RedisBungee;

import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
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. */
class NameFetcher implements Callable<Map<UUID, String>> {
    private static final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
    private final List<UUID> uuids;

    public NameFetcher(List<UUID> uuids) {
        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;
    }
}
@@ -358,29 +358,22 @@
 mon.
-collect.ImmutableList
+io.ByteStreams
 ;%0Aim
@@ -493,352 +493,156 @@
 io.I
-nputStreamReader;%0Aimport java.net.HttpURLConnection;%0Aimport java.net.URL;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.UUID;%0Aimport java.util.concurrent.Callable;%0A%0A/* Credits to evilmidget38 for this class. I modified it to use Gson. */%0Aclass NameFetcher implements Callable%3CMap%3CUUID, String%3E%3E
+OException;%0Aimport java.lang.reflect.Type;%0Aimport java.net.URL;%0Aimport java.net.URLConnection;%0Aimport java.util.*;%0A%0Apublic class NameFetcher
  %7B%0A    p
 riva
@@ -641,22 +641,21 @@
    p
-rivate
+ublic
  static 
 fina
@@ -654,283 +654,50 @@
 tic 
-final String PROFILE_URL = %22https://sessionserver.mojang.com/session/minecraft/profile/%22;%0A    private final List%3CUUID%3E uuids;%0A%0A    public NameFetcher(List%3C
+List%3CString%3E nameHistoryFromUuid(
 UUID
-%3E
  uuid
-s) %7B%0A        this.uuids = ImmutableList.copyOf(uuids);%0A    %7D%0A%0A    @Override%0A    public Map%3CUUID, String%3E call(
 ) th
@@ -701,16 +701,18 @@
  throws 
+IO
 Exceptio
@@ -727,175 +727,82 @@
     
-Map%3CUUID, String%3E uuidStringMap = new HashMap%3C%3E();%0A        for (UUID uuid : uuids) %7B%0A            HttpURLConnection connection = (HttpURLConnection) new URL(PROFILE_URL
+URLConnection connection = new URL(%22https://api.mojang.com/user/profiles/%22
  + u
@@ -832,16 +832,41 @@
 %22-%22, %22%22)
+.toLowerCase() + %22/names%22
 ).openCo
@@ -889,177 +889,143 @@
     
-    Map%3CString, String%3E response = RedisBungee.getGson().fromJson(new InputStreamReader(connection.getInputStream()), new TypeToken%3CMap%3CString, String%3E%3E() %7B%0A            
+String text = new String(ByteStreams.toByteArray(connection.getInputStream()));%0A        Type listType = new TypeToken%3CList%3CString%3E%3E() %7B
 %7D.ge
@@ -1031,17 +1031,16 @@
 etType()
-)
 ;%0A      
@@ -1045,447 +1045,61 @@
     
-   
- String name = response.get(%22name%22);%0A            if (name == null) %7B%0A                continue;%0A            %7D%0A            String cause = response.get(%22cause%22);%0A            String errorMessage = response.get(%22errorMessage%22);%0A            if (cause != null && cause.length() %3E 0) %7B%0A                throw new IllegalStateException(errorMessage);%0A            %7D%0A            uuidStringMap.put(uuid, name);%0A        %7D%0A        return uuidStringMap
+return RedisBungee.getGson().fromJson(text, listType)
 ;%0A  

Revert "Revert to old method as the new method has changed"