package com.programmingwizzard.charrizard.bot.commands;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.programmingwizzard.charrizard.bot.commands.basic.CMessage;
import com.programmingwizzard.charrizard.bot.commands.basic.Command;
import com.programmingwizzard.charrizard.bot.response.skript.SkriptServerResponse;
import com.programmingwizzard.charrizard.bot.response.skript.SkriptServerResponses;
import com.programmingwizzard.charrizard.utils.BooleanUtils;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.exceptions.RateLimitedException;

import java.awt.*;

/*
 * @author ProgrammingWizzard
 * @date 06.02.2017
 */
public class MinecraftCommand extends Command
{
    private final SkriptServerResponses responses;

    public MinecraftCommand()
    {
        super("minecraft");
        this.responses = new SkriptServerResponses();
    }

    @Override
    public void handle(CMessage message, String[] args) throws RateLimitedException
    {
        TextChannel channel = message.getChannel();
        if (args.length == 0 || args.length == 1)
        {
            sendUsage(message, "!minecraft <status>");
            return;
        }
        switch (args[1])
        {
            case "status":
                this.checkStatus(message, args);
                break;
            default:
                sendUsage(message, "!minecraft <status>");
                break;
        }
    }

    private void checkStatus(CMessage message, String[] args)
    {
        TextChannel channel = message.getChannel();
        if (args.length != 3)
        {
            sendUsage(message, "!minecraft status <ip>");
            return;
        }
        String server = args[2];
        if (server == null || server.isEmpty())
        {
            sendUsage(message, "!minecraft status <ip>");
            return;
        }

        responses.call(server, response -> {
            if (response == null) {
                sendError(message, "An error occurred while connecting with api.skript.pl");
                return;
            }

            String info;
            if (response.isOnline()) {
                StringBuilder list = new StringBuilder();
                for (String player : response.getPlayersList()) {
                    list.append(", ").append(player);
                }
                info =
                    "**Online:** YES\n" +
                    String.format("**Latency:** %.2fms\n", response.getLatency()) +
                    String.format("**Version:** %s (Protocol #%d)\n", response.getVersion(), response.getProtocol()) +
                    String.format("**Players (%d/%d):** %s\n", response.getOnlinePlayers(), response.getMaxPlayers(), list.substring(2)) +
                    String.format("**Description:**\n %s\n", response.getDescription());
            } else {
                info = "**Online:** NO";
            }

            EmbedBuilder builder = getEmbedBuilder()
                .setTitle("Charrizard")
                .setFooter("© 2017 Charrizard contributors", null)
                .setUrl("https://github.com/ProgrammingWizzard/Charrizard/")
                .setColor(new Color(0, 250, 0))
                .addField("Minecraft Status: " + server, info, true);
            sendEmbedMessage(message, builder);
        });
    }
}

@@ -530,16 +530,67 @@
 uilder;%0A
+import net.dv8tion.jda.core.entities.MessageEmbed;%0A
 import n
@@ -711,16 +711,41 @@
 a.awt.*;
+%0Aimport java.util.Base64;
 %0A%0A/*%0A * 
@@ -2970,16 +2970,53 @@
 ption())
+ +%0A                    %22**Favicon:**%22
 ;%0A      
@@ -3068,16 +3068,30 @@
 ne:** NO
+%5Cn**Favicon:**
 %22;%0A     
@@ -3385,16 +3385,113 @@
 50, 0))%0A
+                .setImage(%22https://api.skript.pl/server/%22 + response.getAddress() + %22/icon.png%22)%0A
         

Add favicon to !minecraft status