package com.techcavern.wavetact.ircCommands.minecraft;

import com.techcavern.wavetact.annot.IRCCMD;
import com.techcavern.wavetact.objects.IRCCommand;
import com.techcavern.wavetact.utils.GeneralUtils;
import com.techcavern.wavetact.utils.IRCUtils;
import org.apache.commons.lang3.text.WordUtils;
import org.pircbotx.Channel;
import org.pircbotx.PircBotX;
import org.pircbotx.User;

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

@IRCCMD
public class MCStatus extends IRCCommand {

    public MCStatus() {
        super(GeneralUtils.toArray("mcstatus mcs"), 0, null, "Checks status of mojang servers", false);
    }

    @Override
    public void onCommand(String command, User user, PircBotX network, String prefix, Channel channel, boolean isPrivate, int userPermLevel, String... args) throws Exception {
        String result;
        URL url = new URL("https://status.mojang.com/check");
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        result = reader.readLine().replace("\"},{\"", " - ").replace("\":\"", ": ").replace("green", "Online").replace("red", "Offline").replace("[{\"", "").replace("\"}]", "").replace(".minecraft.net", "").replace(".mojang.com", "").replace("server", " Server").replace(".net", "");
        result = WordUtils.capitalizeFully(result);
        if (result != null) {
            IRCUtils.sendMessage(user, network, channel, result, prefix);
        } else {
            IRCUtils.sendError(user, network, channel, "MC status currently unavailable", prefix);
        }
    }

}


@@ -49,16 +49,50 @@
 craft;%0A%0A
+import com.google.gson.JsonArray;%0A
 import c
@@ -273,24 +273,69 @@
 s.IRCUtils;%0A
+import org.apache.commons.lang3.StringUtils;%0A
 import org.a
@@ -472,59 +472,22 @@
 ava.
-io.BufferedReader;%0Aimport java.io.InputStreamReader
+util.ArrayList
 ;%0Aim
@@ -500,15 +500,17 @@
 ava.
-net.URL
+util.List
 ;%0A%0A@
@@ -897,511 +897,1242 @@
     
+List%3C
 String
+%3E
  result
-;%0A        URL url = new URL(%22https://status.mojang.com/check%22);%0A        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));%0A        result = reader.readLine().replace(%22%5C%22%7D,%7B%5C%22%22, %22 - %22).replace(%22%5C%22:%5C%22%22, %22: %22).replace(%22green%22, %22Online%22).replace(%22red%22, %22Offline%22).replace(%22%5B%7B%5C%22%22, %22%22).replace(%22%5C%22%7D%5D%22, %22%22).replace(%22.minecraft.net%22, %22%22).replace(%22.mojang.com%22, %22%22).replace(%22server%22, %22 Server%22).replace(%22.net%22, %22%22);%0A        result = WordUtils.capitalizeFully(result
+ = new ArrayList%3C%3E();%0A        JsonArray mcstatus = GeneralUtils.getJsonArray(%22https://status.mojang.com/check%22);%0A        mcstatus.forEach(status -%3E %7B%0A            String name = status.getAsJsonObject().entrySet().iterator().next().getKey().toString();%0A            if (name.equalsIgnoreCase(%22minecraft.net%22)) %7B%0A                name = %22Website%22;%0A            %7D else if (name.equalsIgnoreCase(%22api.mojang.com%22)) %7B%0A                name = %22API%22;%0A            %7D else if (name.equalsIgnoreCase(%22authserver.mojang.com%22)) %7B%0A                name = %22AuthServer%22;%0A            %7D else if (name.equalsIgnoreCase(%22sessionserver.mojang.com%22)) %7B%0A                name = %22SessionServer%22;%0A            %7D else %7B%0A                name = WordUtils.capitalize(name.replace(%22.minecraft.net%22, %22%22).replace(%22.mojang.com%22, %22%22));%0A            %7D%0A            String value = status.getAsJsonObject().entrySet().iterator().next().getValue().getAsString();%0A            if (value.equalsIgnoreCase(%22green%22)) %7B%0A                value = %22Online%22;%0A            %7D else if (value.equalsIgnoreCase(%22yellow%22)) %7B%0A                value = %22Slow%22;%0A            %7D else %7B%0A                value = %22Offline%22;%0A            %7D%0A            result.add(name + %22: %22 + value);%0A        %7D
 );%0A 
@@ -2217,22 +2217,47 @@
 hannel, 
-result
+StringUtils.join(result, %22 - %22)
 , prefix

Reformat MC Status