package com.newhive.scammerradar.helper.subhelper;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.newhive.scammerradar.exceptions.ProfileNotFoundException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.regex.Pattern;
import org.jetbrains.annotations.Nullable;

public class UpdateSubHelper {
   private String baseURLUUID = "https://api.minecraftservices.com/minecraft/profile/lookup/";
   private String baseURLNAME = "https://api.minecraftservices.com/users/profiles/minecraft/";

   public String getName(String uuid) throws ProfileNotFoundException {
      try {
         BufferedReader reader = new BufferedReader(new InputStreamReader((new URL(this.baseURLUUID + uuid)).openStream()));
         JsonObject json = (JsonObject)(new Gson()).fromJson(reader, JsonObject.class);
         if (json == null) {
            throw new Exception();
         } else if (!json.has("name")) {
            throw new Exception();
         } else {
            return json.get("name").getAsString();
         }
      } catch (Exception var4) {
         throw new ProfileNotFoundException("");
      }
   }

   public @Nullable String getUUID(String name) throws ProfileNotFoundException {
      try {
         BufferedReader reader = new BufferedReader(new InputStreamReader((new URL(this.baseURLNAME + name)).openStream()));
         JsonObject json = (JsonObject)(new Gson()).fromJson(reader, JsonObject.class);
         if (json == null) {
            throw new Exception();
         } else if (!json.has("id")) {
            throw new Exception();
         } else {
            String uuid = json.get("id").getAsString();
            return Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})").matcher(uuid).replaceAll("$1-$2-$3-$4-$5");
         }
      } catch (Exception var5) {
         throw new ProfileNotFoundException("");
      }
   }
}
