package com.techcavern.wavetact.ircCommands.minecraft;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
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;

@IRCCMD
public class MCMods extends IRCCommand {

    public MCMods() {
        super(GeneralUtils.toArray("mcmods mcmod"), 0, "mcmods (mc version#) [mod name]", "Gets info on a minecraft mod", false);
    }

    @Override
    public void onCommand(User user, PircBotX network, String prefix, Channel channel, boolean isPrivate, int userPermLevel, String... args) throws Exception {
        JsonArray versions = GeneralUtils.getJsonArray("http://bot.notenoughmods.com/?json");
        String version = "";
        String modname = "";
        JsonArray mods = null;
        for (int i = 0; i < versions.size(); i++) {
            String vers = versions.get(i).getAsString();
            if (vers.contains(args[0])) {
                version = vers;
                modname = args[1].toLowerCase();
            }
        }

        if (version.isEmpty()) {
            int arraysize = 0;
            int versionsize = versions.size();
            while (arraysize <= 100) {
                versionsize = versionsize - 1;
                version = versions.get(versionsize).getAsString();
                mods = GeneralUtils.getJsonArray("http://bot.notenoughmods.com/" + version + ".json");
                arraysize = mods.size();
            }
            modname = args[0].toLowerCase();
        } else {
            mods = GeneralUtils.getJsonArray("http://bot.notenoughmods.com/" + version + ".json");
        }
        int total = 0;
        for (int i = 0; i < mods.size(); i++) {
            JsonObject mod = mods.get(i).getAsJsonObject();
            if (mod.get("name").getAsString().toLowerCase().contains(modname)) {
                String Version = mod.get("version").getAsString();
                String Name = mod.get("name").getAsString();
                String Link = mod.get("shorturl").getAsString();
                String Author = mod.get("author").getAsString();
                if (Link.isEmpty()) {
                    Link = mod.get("longurl").getAsString();
                }
                if (total < 3) {
                    IRCUtils.sendMessage(user, network, channel, "[" + Version + "] " + Name + " by " + Author + " - " + Link, prefix);
                }
                total++;
            }
        }
        if (total == 0) {
            ErrorUtils.sendError(user, "No mods found");
        }
    }
}



@@ -357,24 +357,68 @@
 s.IRCUtils;%0A
+import org.apache.commons.lang3.ArrayUtils;%0A
 import org.p
@@ -434,16 +434,16 @@
 hannel;%0A
-
 import o
@@ -625,16 +625,24 @@
  %22mcmods
+ (--dev)
  (mc ver
@@ -968,32 +968,63 @@
 ds.com/?json%22);%0A
+        boolean isDev = false;%0A
         String v
@@ -1096,16 +1096,136 @@
 = null;%0A
+        if(args%5B0%5D.equals(%22--dev%22))%7B%0A            isDev = true;%0A            args = ArrayUtils.remove(args, 0);%0A        %7D%0A
         
@@ -1468,25 +1468,24 @@
 %7D%0A        %7D%0A
-%0A
         if (
@@ -2300,16 +2300,162 @@
  String 
+ModVersion = %22%22;%0A                if(isDev)%0A                ModVersion = mod.get(%22dev%22).getAsString();%0A                else%0A                    Mod
 Version 
@@ -2827,24 +2827,76 @@
 otal %3C 3) %7B%0A
+                    if(!ModVersion.isEmpty()) %7B%0A    
             
@@ -2954,16 +2954,19 @@
 , %22%5B%22 + 
+Mod
 Version 
@@ -3022,16 +3022,53 @@
 refix);%0A
+                        total++;%0A    
         
@@ -3089,32 +3089,29 @@
             
-total++;
+    %7D
 %0A           

Add Dev Version to MCMods (Fixes #103)