From d9e49fe3ec3f0a869a2b3610d903c3b3ed9213b0 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Sun, 29 Jan 2023 11:42:07 +0000 Subject: [PATCH] Apply spotless --- .../common/utils/GolemEnumHelper.java | 52 ++++++------------- .../gadomancy/common/utils/Injector.java | 26 +++++----- 2 files changed, 29 insertions(+), 49 deletions(-) diff --git a/src/main/java/makeo/gadomancy/common/utils/GolemEnumHelper.java b/src/main/java/makeo/gadomancy/common/utils/GolemEnumHelper.java index b052484..153ccc2 100644 --- a/src/main/java/makeo/gadomancy/common/utils/GolemEnumHelper.java +++ b/src/main/java/makeo/gadomancy/common/utils/GolemEnumHelper.java @@ -1,27 +1,29 @@ package makeo.gadomancy.common.utils; -import cpw.mods.fml.relauncher.Side; import java.lang.reflect.Field; import java.util.Arrays; import java.util.HashMap; import java.util.Map; + import makeo.gadomancy.api.GadomancyApi; import makeo.gadomancy.api.golems.AdditionalGolemType; import makeo.gadomancy.client.events.ResourceReloadListener; import makeo.gadomancy.common.Gadomancy; import makeo.gadomancy.common.entities.golems.types.RemovedGolemType; + import net.minecraftforge.common.util.EnumHelper; + import thaumcraft.common.entities.golems.EnumGolemType; +import cpw.mods.fml.relauncher.Side; /** - * This class is part of the Gadomancy Mod - * Gadomancy is Open Source and distributed under the - * GNU LESSER GENERAL PUBLIC LICENSE - * for more read the LICENSE file + * This class is part of the Gadomancy Mod Gadomancy is Open Source and distributed under the GNU LESSER GENERAL PUBLIC + * LICENSE for more read the LICENSE file * * Created by makeo @ 29.07.2015 01:07 */ public class GolemEnumHelper { + private static final RemovedGolemType REMOVED_GOLEM_TYPE = new RemovedGolemType(); private static final Injector INJECTOR = new Injector(EnumGolemType.class); private static final Injector ENUM_INJECTOR = new Injector(Enum.class); @@ -43,18 +45,8 @@ private static Field getValuesField() { return GolemEnumHelper.valuesField; } - private static final Class[] ENUM_PARAMS = { - String.class, - int.class, - int.class, - int.class, - float.class, - boolean.class, - int.class, - int.class, - int.class, - int.class - }; + private static final Class[] ENUM_PARAMS = { String.class, int.class, int.class, int.class, float.class, + boolean.class, int.class, int.class, int.class, int.class }; private static Field ordinalField; @@ -62,26 +54,17 @@ public static Field getOrdinalField() { if (GolemEnumHelper.ordinalField == null) { try { GolemEnumHelper.ordinalField = Enum.class.getDeclaredField("ordinal"); - } catch (NoSuchFieldException ignored) { - } + } catch (NoSuchFieldException ignored) {} } return GolemEnumHelper.ordinalField; } private static EnumGolemType createEnum(String name, int ordinal, AdditionalGolemType type) { resetEnumCache(); - return INJECTOR.invokeUnsafeConstructor(ENUM_PARAMS, new Object[] { - name, - ordinal, - type.maxHealth, - type.armor, - type.movementSpeed, - type.fireResist, - type.upgradeAmount, - type.carryLimit, - type.regenDelay, - type.strength - }); + return INJECTOR.invokeUnsafeConstructor( + ENUM_PARAMS, + new Object[] { name, ordinal, type.maxHealth, type.armor, type.movementSpeed, type.fireResist, + type.upgradeAmount, type.carryLimit, type.regenDelay, type.strength }); } private static void resetEnumCache() { @@ -134,8 +117,7 @@ private static void setValues(EnumGolemType[] values) { try { EnumHelper.setFailsafeFieldValue(GolemEnumHelper.getValuesField(), null, values); resetEnumCache(); - } catch (Exception ignored) { - } + } catch (Exception ignored) {} } public static EnumGolemType addGolemType(String name, AdditionalGolemType type) { @@ -196,8 +178,8 @@ public static void reorderEnum(Map mapping) { } private static void resetEnum() { - EnumGolemType[] newValues = - Arrays.copyOfRange(EnumGolemType.values(), 0, GolemEnumHelper.calcDefaultGolemCount()); + EnumGolemType[] newValues = Arrays + .copyOfRange(EnumGolemType.values(), 0, GolemEnumHelper.calcDefaultGolemCount()); GolemEnumHelper.setValues(newValues); resetEnumCache(); } diff --git a/src/main/java/makeo/gadomancy/common/utils/Injector.java b/src/main/java/makeo/gadomancy/common/utils/Injector.java index 6519f90..f8d57fa 100644 --- a/src/main/java/makeo/gadomancy/common/utils/Injector.java +++ b/src/main/java/makeo/gadomancy/common/utils/Injector.java @@ -1,23 +1,24 @@ package makeo.gadomancy.common.utils; -import com.google.common.base.Throwables; -import cpw.mods.fml.relauncher.ReflectionHelper; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; + import sun.misc.Unsafe; +import com.google.common.base.Throwables; +import cpw.mods.fml.relauncher.ReflectionHelper; + /** - * This class is part of the Gadomancy Mod - * Gadomancy is Open Source and distributed under the - * GNU LESSER GENERAL PUBLIC LICENSE - * for more read the LICENSE file + * This class is part of the Gadomancy Mod Gadomancy is Open Source and distributed under the GNU LESSER GENERAL PUBLIC + * LICENSE for more read the LICENSE file * * Created by makeo @ 02.12.13 18:45 */ public class Injector { + static final Unsafe UNSAFE; static { @@ -81,7 +82,7 @@ public T invokeConstructor(Object... params) { } public T invokeConstructor(Class clazz, Object param) { - return this.invokeConstructor(new Class[] {clazz}, param); + return this.invokeConstructor(new Class[] { clazz }, param); } public T invokeConstructor(Class[] classes, Object... params) { @@ -112,7 +113,7 @@ public T invokeMethod(String name, Object... params) { } public T invokeMethod(String name, Class clazz, Object param) { - return this.invokeMethod(name, new Class[] {clazz}, param); + return this.invokeMethod(name, new Class[] { clazz }, param); } public T invokeMethod(String name, Class[] classes, Object... params) { @@ -161,8 +162,7 @@ public boolean setField(Field field, Object value) { if (object == null) { base = UNSAFE.staticFieldBase(field); } - final long offset = Modifier.isStatic(field.getModifiers()) - ? UNSAFE.staticFieldOffset(field) + final long offset = Modifier.isStatic(field.getModifiers()) ? UNSAFE.staticFieldOffset(field) : UNSAFE.objectFieldOffset(field); UNSAFE.putObject(base, offset, value); return true; @@ -187,8 +187,7 @@ public boolean setFieldInt(Field field, int value) { if (object == null) { base = UNSAFE.staticFieldBase(field); } - final long offset = Modifier.isStatic(field.getModifiers()) - ? UNSAFE.staticFieldOffset(field) + final long offset = Modifier.isStatic(field.getModifiers()) ? UNSAFE.staticFieldOffset(field) : UNSAFE.objectFieldOffset(field); UNSAFE.putInt(base, offset, value); return true; @@ -233,8 +232,7 @@ public Field findField(Class type) { public static Method findMethod(Class clazz, Class returnType, Class[] paramTypes) { for (Method m : clazz.getDeclaredMethods()) { - if (Arrays.equals(m.getParameterTypes(), paramTypes) - && m.getReturnType().equals(returnType)) { + if (Arrays.equals(m.getParameterTypes(), paramTypes) && m.getReturnType().equals(returnType)) { return m; } }