package com.techcavern.wavetact.ircCommands.minecraft;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.techcavern.wavetact.annot.IRCCMD;
import com.techcavern.wavetact.objects.IRCCommand;
import com.techcavern.wavetact.utils.ErrorUtils;
import com.techcavern.wavetact.utils.GeneralUtils;
import com.techcavern.wavetact.utils.IRCUtils;
import org.pircbotx.Channel;
import org.pircbotx.PircBotX;
import org.pircbotx.User;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;

@IRCCMD
public class MCAccountInfo extends IRCCommand {

    public MCAccountInfo() {
        super(GeneralUtils.toArray("mcaccountinfo mca mcuserinfo mcpremium mcuuid mcmigrated"), 0, "mcaccountinfo [user]", "Gets info on a minecraft account", false);
    }

    @Override
    public void onCommand(String command, User user, PircBotX network, String prefix, Channel channel, boolean isPrivate, int userPermLevel, String... args) throws Exception {
        URL url = new URL("https://api.mojang.com/profiles/minecraft");

        String payload = "[\"" + args[0] + "\",\"egewewhewhwe\"]";
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "application/json");
        OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
        writer.write(payload);
        writer.close();
        BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String result = "";
        String line;
        while ((line = br.readLine()) != null) {
            result += line.replaceAll("\n", " ") + "\n";
        }
        br.close();
        connection.disconnect();
        JsonArray mcapipre = new JsonParser().parse(result).getAsJsonArray();
        if (mcapipre.size() > 0) {
            JsonObject mcapi = mcapipre.get(0).getAsJsonObject();
            String User = mcapi.get("name").getAsString();
            String UUID = mcapi.get("id").getAsString();
            String Premium = "True";
            if (mcapi.get("demo") != null && mcapi.get("legacy").getAsString().equalsIgnoreCase("True")) {
                Premium = "False";
            }
            String Migrated = "True";
            if (mcapi.get("legacy") != null && mcapi.get("legacy").getAsString().equalsIgnoreCase("True")) {
                Migrated = "False";
            }
            IRCUtils.sendMessage(user, network, channel, "[" + User + "] " + "UUID: " + UUID + " - " + "Paid: " + Premium + " - " + "Mojang Account: " + Migrated, prefix);
        } else {
            ErrorUtils.sendError(user, "User does not exist");
        }
    }

}

@@ -411,237 +411,169 @@
 org.
-pircbotx.Channel;%0Aimport org.pircbotx.PircBotX;%0Aimport org.pircbotx.User;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.InputStreamReader;%0Aimport java.io.OutputStreamWriter;%0Aimport java.net.HttpURLConnection;%0Aimport java.net.URL
+apache.http.client.fluent.Request;%0Aimport org.apache.http.entity.ContentType;%0Aimport org.pircbotx.Channel;%0Aimport org.pircbotx.PircBotX;%0Aimport org.pircbotx.User
 ;%0A%0A@
@@ -1033,25 +1033,36 @@
     
-URL url = new URL
+String result = Request.Post
 (%22ht
@@ -1106,19 +1106,23 @@
 ft%22)
-;%0A%0A
+%0A      
         
 Stri
@@ -1121,25 +1121,22 @@
     
-String payload = 
+  .bodyString(
 %22%5B%5C%22
@@ -1175,754 +1175,108 @@
 %5C%22%5D%22
-;%0A        HttpURLConnection connection = (HttpURLConnection) url.openConnection();%0A        connection.setDoInput(true);%0A        connection.setDoOutput(true);%0A        connection.setRequestMethod(%22POST%22);%0A        connection.setRequestProperty(%22Content-Type%22, %22application/json%22);%0A        OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), %22UTF-8%22);%0A        writer.write(payload);%0A        writer.close();%0A        BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));%0A        String result = %22%22;%0A        String line;%0A        while ((line = br.readLine()) != null) %7B%0A            result += line.replaceAll(%22%5Cn%22, %22 %22) + %22%5Cn%22;%0A        %7D%0A        br.close();%0A        connection.disconnect
+, ContentType.APPLICATION_JSON)%0A                .execute()%0A                .returnContent().toString
 ();%0A

Switch to HTTPClient api from Apache