Skip to content

Commit

Permalink
Apply spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenraven committed Jan 29, 2023
1 parent 63e7eb2 commit d9e49fe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 49 deletions.
52 changes: 17 additions & 35 deletions 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);
Expand All @@ -43,45 +45,26 @@ 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;

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() {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -196,8 +178,8 @@ public static void reorderEnum(Map<String, Integer> 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();
}
Expand Down
26 changes: 12 additions & 14 deletions 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 {
Expand Down Expand Up @@ -81,7 +82,7 @@ public <T> T invokeConstructor(Object... params) {
}

public <T> T invokeConstructor(Class<?> clazz, Object param) {
return this.invokeConstructor(new Class[] {clazz}, param);
return this.invokeConstructor(new Class[] { clazz }, param);
}

public <T> T invokeConstructor(Class<?>[] classes, Object... params) {
Expand Down Expand Up @@ -112,7 +113,7 @@ public <T> T invokeMethod(String name, Object... params) {
}

public <T> 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> T invokeMethod(String name, Class[] classes, Object... params) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit d9e49fe

Please sign in to comment.