Restore Minecraft 1.7 compatibility, hopefully.

This commit is contained in:
Olof Larsson 2016-06-18 09:17:24 +02:00
parent 3c23493eb3
commit 4184e568fc
No known key found for this signature in database
GPG Key ID: BBEF14F97DA52474

View File

@ -97,6 +97,8 @@ public class RegistryType
public static Type<?> getType(Field field, java.lang.reflect.Type fieldType, boolean strictThrow) public static Type<?> getType(Field field, java.lang.reflect.Type fieldType, boolean strictThrow)
{ {
if (field != null) if (field != null)
{
try
{ {
EditorType annotationType = ReflectionUtil.getAnnotation(field, EditorType.class); EditorType annotationType = ReflectionUtil.getAnnotation(field, EditorType.class);
if (annotationType != null) if (annotationType != null)
@ -105,6 +107,14 @@ public class RegistryType
Type<?> type = ReflectionUtil.getSingletonInstance(typeClass); Type<?> type = ReflectionUtil.getSingletonInstance(typeClass);
return type; return type;
} }
}
catch (Throwable t)
{
// This has to do with backwards compatibility (Usually 1.7).
// The annotations may trigger creation of type class instances.
// Those type classes may refer to Bukkit classes not present.
// This issue was first encountered for TypeDataItemStack.
}
if (fieldType == null) if (fieldType == null)
{ {
@ -186,21 +196,35 @@ public class RegistryType
public static List<Type<?>> getInnerTypes(Field field, java.lang.reflect.Type fieldType, int amountRequired) public static List<Type<?>> getInnerTypes(Field field, java.lang.reflect.Type fieldType, int amountRequired)
{ {
// Create // Annotation
List<Type<?>> ret = new MassiveList<>();
// Fill > Annotation
if (field != null) if (field != null)
{
try
{ {
EditorTypeInner annotation = ReflectionUtil.getAnnotation(field, EditorTypeInner.class); EditorTypeInner annotation = ReflectionUtil.getAnnotation(field, EditorTypeInner.class);
if (annotation != null) if (annotation != null)
{ {
// Create
List<Type<?>> ret = new MassiveList<>();
// Fill
Class<?>[] innerTypeClasses = annotation.value(); Class<?>[] innerTypeClasses = annotation.value();
for (Class<?> innerTypeClass : innerTypeClasses) for (Class<?> innerTypeClass : innerTypeClasses)
{ {
Type<?> innerType = ReflectionUtil.getSingletonInstance(innerTypeClass); Type<?> innerType = ReflectionUtil.getSingletonInstance(innerTypeClass);
ret.add(innerType); ret.add(innerType);
} }
// Return
return ret;
}
}
catch (Throwable t)
{
// This has to do with backwards compatibility (Usually 1.7).
// The annotations may trigger creation of type class instances.
// Those type classes may refer to Bukkit classes not present.
// This issue was first encountered for TypeDataItemStack.
} }
if (fieldType == null) if (fieldType == null)
@ -209,11 +233,15 @@ public class RegistryType
} }
} }
// Fill > Reflection // Reflection
if (fieldType != null) if (fieldType != null)
{ {
if (fieldType instanceof ParameterizedType) if (fieldType instanceof ParameterizedType)
{ {
// Create
List<Type<?>> ret = new MassiveList<>();
// Fill
ParameterizedType parameterizedType = (ParameterizedType)fieldType; ParameterizedType parameterizedType = (ParameterizedType)fieldType;
int count = 0; int count = 0;
for (java.lang.reflect.Type actualTypeArgument : parameterizedType.getActualTypeArguments()) for (java.lang.reflect.Type actualTypeArgument : parameterizedType.getActualTypeArguments())
@ -223,13 +251,17 @@ public class RegistryType
ret.add(innerType); ret.add(innerType);
count++; count++;
} }
}
}
// Return // Return
return ret; return ret;
} }
throw new IllegalArgumentException("Not ParameterizedType: " + fieldType);
}
throw new IllegalArgumentException("Failure");
}
// -------------------------------------------- // // -------------------------------------------- //
// DEFAULTS // DEFAULTS
// -------------------------------------------- // // -------------------------------------------- //