<commit_before>package com.forgeessentials.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.UUID;

import javax.net.ssl.HttpsURLConnection;

import com.forgeessentials.util.output.LoggingHandler;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;

public class UserIdentUtils
{

    public static UUID hexStringToUUID(String s)
    {
        if (s.length() != 32)
            throw new IllegalArgumentException();
        byte[] data = new byte[32];
        for (int i = 0; i < 32; i++)
        {
            data[i] = (byte) s.charAt(i);
        }
        return UUID.nameUUIDFromBytes(data);
    }

    public static UUID stringToUUID(String s)
    {
        if (s.length() == 32)
            return hexStringToUUID(s);
        else
            return UUID.fromString(s);

    }

    public static UUID resolveMissingUUID(String name)
    {
        String url = "https://api.mojang.com/users/profiles/minecraft/" + name;
        String data = fetchData(url, "id");
        if (data != null)
            return stringToUUID(data);
        return null;
    }

    public static String resolveMissingUsername(UUID id)
    {
        String url = "https://api.mojang.com/user/profiles/" + id.toString().replace("-", "") + "/names";
        return fetchData(url, "name");
    }

    public static String fetchData(String url, String id)
    {
        try
        {
            LoggingHandler.felog.debug("Fetching " + id + " from " + url);
            URL uri = new URL(url);
            HttpsURLConnection huc = (HttpsURLConnection) uri.openConnection();
            InputStream is;
            try (JsonReader jr = new JsonReader(new InputStreamReader(is = huc.getInputStream())))
            {
                if (is.available() > 0 && jr.hasNext())
                {
                    jr.beginObject();
                    String name = null;

                    while (jr.hasNext())
                        if (jr.peek() == JsonToken.NAME)
                            name = jr.nextName();
                        else
                        {
                            if (jr.peek() == JsonToken.STRING)
                                if (name.equals(id))
                                    return jr.nextString();
                            name = null;
                        }
                    jr.endObject();
                }
            }
            return null;
        }
        catch (MalformedURLException e)
        {
            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return null;
    }

}<commit_msg>Fixes #2252 #2253<commit_after>package com.forgeessentials.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.UUID;

import javax.net.ssl.HttpsURLConnection;

import com.forgeessentials.util.output.LoggingHandler;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;

public class UserIdentUtils
{

    public static String reformatUUID(String s)
    {
        if (s.length() != 32)
            throw new IllegalArgumentException();
        return s.substring(0,8) + "-" + s.substring(8,12) + "-" + s.substring(12,16) + "-" + s.substring(16,20) + "-" + s.substring(20,32);
    }

    public static UUID stringToUUID(String s)
    {
        if (s.length() == 32)
            s = reformatUUID(s);
        return UUID.fromString(s);

    }

    public static UUID resolveMissingUUID(String name)
    {
        String url = "https://api.mojang.com/users/profiles/minecraft/" + name;
        String data = fetchData(url, "id");
        if (data != null)
            return stringToUUID(data);
        return null;
    }

    public static String resolveMissingUsername(UUID id)
    {
        String url = "https://api.mojang.com/user/profiles/" + id.toString().replace("-", "") + "/names";
        return fetchData(url, "name");
    }

    public static String fetchData(String url, String id)
    {
        try
        {
            LoggingHandler.felog.debug("Fetching " + id + " from " + url);
            URL uri = new URL(url);
            HttpsURLConnection huc = (HttpsURLConnection) uri.openConnection();
            InputStream is;
            try (JsonReader jr = new JsonReader(new InputStreamReader(is = huc.getInputStream())))
            {
                if (is.available() > 0 && jr.hasNext())
                {
                    if (jr.peek() == JsonToken.BEGIN_ARRAY)
                        jr.beginArray();
                    JsonToken t = jr.peek();
                    while (t != JsonToken.END_ARRAY && t != JsonToken.END_DOCUMENT)
                    {
                        jr.beginObject();
                        String name = null;

                        while (jr.hasNext())
                            if (jr.peek() == JsonToken.NAME)
                                name = jr.nextName();
                            else
                            {
                                if (jr.peek() == JsonToken.STRING)
                                    if (name.equals(id))
                                        return jr.nextString();     //This should return before the array finishes
                                name = null;
                            }
                        jr.endObject();
                    }
                    jr.endArray();
                }
            }
            return null;
        }
        catch (MalformedURLException e)
        {
            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return null;
    }

}
{'fraction_non_alphanumeric': 0.11103565365025467, 'fraction_numerical': 0.006791171477079796, 'mean_word_length': 1.4443983402489626, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3869519', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1603, 'n_words': 341}