package mcjty.rftoolsdim.commands;

import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;

public abstract class AbstractRfToolsCommand implements RfToolsCommand {

    protected String fetchString(ICommandSender sender, String[] args, int index, String defaultValue) {
        try {
            return args[index];
        } catch (ArrayIndexOutOfBoundsException e) {
            return defaultValue;
        }
    }

    protected boolean fetchBool(ICommandSender sender, String[] args, int index, boolean defaultValue) {
        boolean value;
        try {
            value = Boolean.valueOf(args[index]);
        } catch (NumberFormatException e) {
            value = false;
            ITextComponent component = new TextComponentString(TextFormatting.RED + "Parameter is not a valid boolean!");
            if (sender instanceof EntityPlayer) {
                ((EntityPlayer) sender).sendStatusMessage(component, false);
            } else {
                sender.sendMessage(component);
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            return defaultValue;
        }
        return value;
    }

    protected int fetchInt(ICommandSender sender, String[] args, int index, int defaultValue) {
        int value;
        try {
            value = Integer.parseInt(args[index]);
        } catch (NumberFormatException e) {
            value = 0;
            ITextComponent component = new TextComponentString(TextFormatting.RED + "Parameter is not a valid integer!");
            if (sender instanceof EntityPlayer) {
                ((EntityPlayer) sender).sendStatusMessage(component, false);
            } else {
                sender.sendMessage(component);
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            return defaultValue;
        }
        return value;
    }

    protected float fetchFloat(ICommandSender sender, String[] args, int index, float defaultValue) {
        float value;
        try {
            value = Float.parseFloat(args[index]);
        } catch (NumberFormatException e) {
            value = 0.0f;
            ITextComponent component = new TextComponentString(TextFormatting.RED + "Parameter is not a valid real number!");
            if (sender instanceof EntityPlayer) {
                ((EntityPlayer) sender).sendStatusMessage(component, false);
            } else {
                sender.sendMessage(component);
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            return defaultValue;
        }
        return value;
    }

    @Override
    public boolean isClientSide() {
        return false;
    }
}

@@ -461,110 +461,45 @@
     
-try %7B%0A            return args%5Bindex%5D;%0A        %7D catch (ArrayIndexOutOfBoundsException e) %7B%0A           
+if(index %3C 0 %7C%7C index %3E= args.length)
  ret
@@ -520,25 +520,43 @@
 ue;%0A        
-%7D
+return args%5Bindex%5D;
 %0A    %7D%0A%0A    
@@ -668,157 +668,202 @@
     
-boolean value;%0A        try %7B%0A            value = Boolean.valueOf(args%5Bindex%5D);%0A        %7D catch (NumberFormatException e) %7B%0A            value = false;
+if(index %3C 0 %7C%7C index %3E= args.length) return defaultValue;%0A        if(args%5Bindex%5D.equalsIgnoreCase(%22true%22)) %7B%0A            return true;%0A        %7D else if(!args%5Bindex%5D.equalsIgnoreCase(%22false%22)) %7B
 %0A   
@@ -1203,114 +1203,28 @@
    %7D
- catch (ArrayIndexOutOfBoundsException e) %7B%0A            return defaultValue;%0A        %7D%0A        return valu
+%0A        return fals
 e;%0A 
@@ -1338,12 +1338,60 @@
    i
-nt v
+f(index %3C 0 %7C%7C index %3E= args.length) return defaultV
 alue
@@ -1418,23 +1418,22 @@
         
-value =
+return
  Integer
@@ -1504,31 +1504,8 @@
 ) %7B%0A
-            value = 0;%0A
     
@@ -1843,117 +1843,31 @@
     
-%7D catch (ArrayIndexOutOfBoundsException e) %7B%0A            return defaultValue;%0A        %7D%0A        return value;
+    return 0;%0A        %7D
 %0A   
@@ -1984,15 +1984,61 @@
     
-float v
+if(index %3C 0 %7C%7C index %3E= args.length) return defaultV
 alue
@@ -2065,23 +2065,22 @@
         
-value =
+return
  Float.p
@@ -2151,34 +2151,8 @@
 ) %7B%0A
-            value = 0.0f;%0A
     
@@ -2494,117 +2494,34 @@
     
-%7D catch (ArrayIndexOutOfBoundsException e) %7B%0A            return defaultValue;%0A        %7D%0A        return value;
+    return 0.0f;%0A        %7D
 %0A   

Refactor argument parsing to use exceptions less