package mods.creepersfire.utility;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

/**
 * @author Strikingwolf, chbachman
 */
public class ReflectionUtil
{
    public static void runMethodsFromObjects(ArrayList<Object> objects, String methodName, Object... args) {
        for (int i = 0; i < objects.size(); i++) {
            runMethodFromObj(objects.get(i), methodName, args );
        }
    }

    public static void runMethodsFromClasses(ArrayList<Class> classes, String methodName, Object... args) {
        for (int i = 0; i < classes.size(); i++) {
            runMethodFromClass(classes.get(i), methodName, args);
        }
    }

    public static void runMethodFromObj(Object obj, String methodName, Object... args) {
        try {
            Class[] params = new Class[args.length];
            for (int i = 0; i < args.length; i++) {
                params[i] = args[i].getClass();
            }
            Method method = obj.getClass().getDeclaredMethod(methodName, params);
            method.setAccessible(true);
            method.invoke(obj, args);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    public static void runMethodFromClass(Class aClass, String methodName, Object... args) {
        try {
            Class[] params = new Class[args.length];
            for (int i = 0; i < args.length; i++) {
                params[i] = args[i].getClass();
            }
            Method method = aClass.getDeclaredMethod(methodName, params);
            method.setAccessible(true);
            method.invoke(aClass, args);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    public static void changeFieldFromObj(Object obj, String fieldName, Object value) {
        Class aClass = obj.getClass();
        Field field;
        try {
            field = aClass.getDeclaredField(fieldName);
            field.setAccessible(true);
            field.set(obj, value);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    public static Object getFieldValFromObj(Object obj, String fieldName) {
        Class aClass = obj.getClass();
        Field field;
        try {
            field = aClass.getDeclaredField(fieldName);
            field.setAccessible(true);
            return field.get(obj);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }
}
@@ -4,17 +4,16 @@
 kage mod
-s
 .creeper
@@ -25,17 +25,16 @@
 .utility
-;
 %0A%0Aimport
@@ -204,19 +204,8 @@
 wolf
-, chbachman
 %0A */
@@ -361,42 +361,31 @@
 or (
-int i = 0; i %3C objects.size(); i++
+Object object : objects
 ) %7B%0A
@@ -419,24 +419,16 @@
 j(object
-s.get(i)
 , method
@@ -437,17 +437,16 @@
 me, args
- 
 );%0A     
@@ -517,16 +517,19 @@
 st%3CClass
+%3C?%3E
 %3E classe
@@ -585,42 +585,33 @@
 or (
-int i = 0; i %3C classes.size(); i++
+Class%3C?%3E aClass : classes
 ) %7B%0A
@@ -645,22 +645,14 @@
 ass(
-c
+aC
 lass
-es.get(i)
 , me
@@ -797,32 +797,35 @@
            Class
+%3C?%3E
 %5B%5D params = new 
@@ -821,32 +821,35 @@
 rams = new Class
+%3C?%3E
 %5Bargs.length%5D;%0A 
@@ -1417,24 +1417,27 @@
 mClass(Class
+%3C?%3E
  aClass, Str
@@ -1501,16 +1501,19 @@
    Class
+%3C?%3E
 %5B%5D param
@@ -1525,16 +1525,19 @@
 ew Class
+%3C?%3E
 %5Bargs.le
@@ -2158,32 +2158,35 @@
  %7B%0A        Class
+%3C?%3E
  aClass = obj.ge
@@ -2620,16 +2620,19 @@
    Class
+%3C?%3E
  aClass 
@@ -3006,8 +3006,9 @@
 %0A    %7D%0A%7D
+%0A

Update ReflectionUtil.java