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

@ -98,12 +98,22 @@ public class RegistryType
{ {
if (field != null) if (field != null)
{ {
EditorType annotationType = ReflectionUtil.getAnnotation(field, EditorType.class); try
if (annotationType != null)
{ {
Class<?> typeClass = annotationType.value(); EditorType annotationType = ReflectionUtil.getAnnotation(field, EditorType.class);
Type<?> type = ReflectionUtil.getSingletonInstance(typeClass); if (annotationType != null)
return type; {
Class<?> typeClass = annotationType.value();
Type<?> type = ReflectionUtil.getSingletonInstance(typeClass);
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,22 +196,36 @@ 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)
{ {
EditorTypeInner annotation = ReflectionUtil.getAnnotation(field, EditorTypeInner.class); try
if (annotation != null)
{ {
Class<?>[] innerTypeClasses = annotation.value(); EditorTypeInner annotation = ReflectionUtil.getAnnotation(field, EditorTypeInner.class);
for (Class<?> innerTypeClass : innerTypeClasses) if (annotation != null)
{ {
Type<?> innerType = ReflectionUtil.getSingletonInstance(innerTypeClass); // Create
ret.add(innerType); List<Type<?>> ret = new MassiveList<>();
// Fill
Class<?>[] innerTypeClasses = annotation.value();
for (Class<?> innerTypeClass : innerTypeClasses)
{
Type<?> innerType = ReflectionUtil.getSingletonInstance(innerTypeClass);
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,11 +251,15 @@ public class RegistryType
ret.add(innerType); ret.add(innerType);
count++; count++;
} }
// Return
return ret;
} }
throw new IllegalArgumentException("Not ParameterizedType: " + fieldType);
} }
// Return throw new IllegalArgumentException("Failure");
return ret;
} }
// -------------------------------------------- // // -------------------------------------------- //