diff options
Diffstat (limited to 'src/main/java/gtPlusPlus/core/util')
3 files changed, 10 insertions, 171 deletions
diff --git a/src/main/java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/main/java/gtPlusPlus/core/util/minecraft/ItemUtils.java index 3565b1c14d..c64686a151 100644 --- a/src/main/java/gtPlusPlus/core/util/minecraft/ItemUtils.java +++ b/src/main/java/gtPlusPlus/core/util/minecraft/ItemUtils.java @@ -72,16 +72,16 @@ public class ItemUtils { return simpleMetaStack(Item.getItemFromBlock(x), meta, i); } - public static ItemStack getSimpleStack(final Item x, final int i) { - return new ItemStack(x, i); + public static ItemStack getSimpleStack(final Item item, final int stackSize) { + return new ItemStack(item, stackSize); } - public static ItemStack getSimpleStack(final ItemStack x, final int i) { - if (x == null) { + public static ItemStack getSimpleStack(final ItemStack stack, final int stackSize) { + if (stack == null) { return null; } - final ItemStack r = x.copy(); - r.stackSize = i; + final ItemStack r = stack.copy(); + r.stackSize = stackSize; return r; } diff --git a/src/main/java/gtPlusPlus/core/util/minecraft/PlayerUtils.java b/src/main/java/gtPlusPlus/core/util/minecraft/PlayerUtils.java index 7ea6af4a23..6f50da5eb2 100644 --- a/src/main/java/gtPlusPlus/core/util/minecraft/PlayerUtils.java +++ b/src/main/java/gtPlusPlus/core/util/minecraft/PlayerUtils.java @@ -19,21 +19,14 @@ import net.minecraftforge.common.util.FakePlayer; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.util.GTUtility; +import gregtech.api.util.ReflectionUtil; import gtPlusPlus.core.util.Utils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; public class PlayerUtils { public static final Map<String, EntityPlayer> mCachedFakePlayers = new WeakHashMap<>(); - private static final Class mThaumcraftFakePlayer; - - static { - if (ReflectionUtils.doesClassExist("thaumcraft.common.lib.FakeThaumcraftPlayer")) { - mThaumcraftFakePlayer = ReflectionUtils.getClass("thaumcraft.common.lib.FakeThaumcraftPlayer"); - } else { - mThaumcraftFakePlayer = null; - } - } + private static final Class<?> mThaumcraftFakePlayer = ReflectionUtil + .getClass("thaumcraft.common.lib.FakeThaumcraftPlayer"); public static List<EntityPlayerMP> getOnlinePlayers() { final List<EntityPlayerMP> onlinePlayers = MinecraftServer.getServer() diff --git a/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 576c236de6..40b32fed86 100644 --- a/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -20,7 +20,6 @@ import gtPlusPlus.core.util.data.StringUtils; @SuppressWarnings({ "unchecked", "rawtypes" }) public class ReflectionUtils { - public static Map<String, Class<?>> mCachedClasses = new LinkedHashMap<>(); public static Map<String, CachedMethod> mCachedMethods = new LinkedHashMap<>(); public static Map<String, CachedField> mCachedFields = new LinkedHashMap<>(); public static Map<String, CachedConstructor> mCachedConstructors = new LinkedHashMap<>(); @@ -74,18 +73,6 @@ public class ReflectionUtils { .getUntypedField(Fields.LookupType.DECLARED_IN_HIERARCHY, field.getName())); } - private static boolean cacheClass(Class<?> aClass) { - if (aClass == null) { - return false; - } - Class<?> y = mCachedClasses.get(aClass.getCanonicalName()); - if (y == null) { - mCachedClasses.put(aClass.getCanonicalName(), aClass); - return true; - } - return false; - } - private static boolean cacheMethod(Class<?> aClass, Method aMethod) { if (aMethod == null) { return false; @@ -154,27 +141,6 @@ public class ReflectionUtils { } /** - * Returns a cached {@link Class} object. - * - * @param aClassCanonicalName - The canonical name of the underlying class. - * @return - Valid, {@link Class} object, or {@link null}. - */ - public static Class<?> getClass(String aClassCanonicalName) { - if (aClassCanonicalName == null || aClassCanonicalName.length() <= 0) { - return null; - } - Class<?> y = mCachedClasses.get(aClassCanonicalName); - if (y == null) { - y = getClass_Internal(aClassCanonicalName); - if (y != null) { - Logger.REFLECTION("Caching Class: " + aClassCanonicalName); - cacheClass(y); - } - } - return y; - } - - /** * Returns a cached {@link Method} object. Wraps {@link #getMethod(Class, String, Class...)}. * * @param aObject - Object containing the Method. @@ -263,10 +229,6 @@ public class ReflectionUtils { * Utility Functions */ - public static boolean doesClassExist(final String classname) { - return isClassPresent(classname); - } - public static void makeFieldAccessible(final Field field) { if (!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic( field.getDeclaringClass() @@ -445,20 +407,6 @@ public class ReflectionUtils { } } - /** - * if (isPresent("com.optionaldependency.DependencyClass")) || This block will never execute when the dependency is - * not present. There is therefore no more risk of code throwing NoClassDefFoundException. - */ - private static boolean isClassPresent(final String className) { - try { - Class.forName(className); - return true; - } catch (final Throwable ex) { - // Class or one of its dependencies is not present... - return false; - } - } - private static Method getMethod_Internal(Class<?> aClass, String aMethodName, Class<?>... aTypes) { Method m = null; try { @@ -561,106 +509,6 @@ public class ReflectionUtils { } } - private static Class<?> getNonPublicClass(final String className) { - Class<?> c = null; - try { - c = Class.forName(className); - } catch (final ClassNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - // full package name --------^^^^^^^^^^ - // or simpler without Class.forName: - // Class<package1.A> c = package1.A.class; - - if (null != c) { - // In our case we need to use - Constructor<?> constructor = null; - try { - constructor = c.getDeclaredConstructor(); - } catch (NoSuchMethodException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - // note: getConstructor() can return only public constructors - // so we needed to search for any Declared constructor - - // now we need to make this constructor accessible - if (null != constructor) { - constructor.setAccessible(true); // ABRACADABRA! - - try { - final Object o = constructor.newInstance(); - return (Class<?>) o; - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException - | InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - return null; - } - - private static Class<?> getClass_Internal(String string) { - Class<?> aClass = null; - if (ReflectionUtils.doesClassExist(string)) { - try { - aClass = Class.forName(string); - } catch (ClassNotFoundException e) { - aClass = getNonPublicClass(string); - } - } - - if (aClass == null) { - String aClassName = ""; - Logger.REFLECTION("Splitting " + string + " to try look for hidden classes."); - String[] aData = string.split("\\."); - Logger.REFLECTION("Obtained " + aData.length + " pieces."); - for (int i = 0; i < (aData.length - 1); i++) { - aClassName += (i > 0) ? "." + aData[i] : "" + aData[i]; - Logger.REFLECTION("Building: " + aClassName); - } - if (aClassName != null && aClassName.length() > 0) { - Logger.REFLECTION("Trying to search '" + aClassName + "' for inner classes."); - Class<?> clazz = ReflectionUtils.getClass(aClassName); - if (clazz != null) { - Class[] y = clazz.getDeclaredClasses(); - if (y == null || y.length <= 0) { - Logger.REFLECTION("No hidden inner classes found."); - return null; - } else { - boolean found = false; - for (Class<?> h : y) { - Logger.REFLECTION("Found hidden inner class: " + h.getCanonicalName()); - if (h.getSimpleName() - .toLowerCase() - .equals(aData[aData.length - 1].toLowerCase())) { - Logger.REFLECTION( - "Found correct class. [" + aData[aData.length - 1] - + "] Caching at correct location: " - + string); - Logger.REFLECTION("Found at location: " + h.getCanonicalName()); - ReflectionUtils.mCachedClasses.put(string, h); - aClass = h; - found = true; - break; - } - } - if (!found) { - return null; - } - } - } else { - return null; - } - } else { - return null; - } - } - return aClass; - } - /** * * Set the value of a field reflectively. @@ -693,9 +541,7 @@ public class ReflectionUtils { T aInstance; try { aInstance = (T) aConstructor.newInstance(aArgs); - if (aInstance != null) { - return aInstance; - } + return aInstance; } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { e.printStackTrace(); |
