diff --git a/TinyProtocol/src/main/java/com/comphenix/tinyprotocol/Reflection.java b/TinyProtocol/src/main/java/com/comphenix/tinyprotocol/Reflection.java
index 14032a3f..304c8960 100644
--- a/TinyProtocol/src/main/java/com/comphenix/tinyprotocol/Reflection.java
+++ b/TinyProtocol/src/main/java/com/comphenix/tinyprotocol/Reflection.java
@@ -3,6 +3,8 @@ package com.comphenix.tinyprotocol;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -177,6 +179,31 @@ public final class Reflection {
throw new IllegalArgumentException("Cannot find field with type " + fieldType);
}
+ /**
+ * Retrieves a field with a given type and parameters. This is most useful
+ * when dealing with Collections.
+ *
+ * @param target the target class.
+ * @param fieldType Type of the field
+ * @param params Variable length array of type parameters
+ * @return The field
+ *
+ * @throws IllegalArgumentException If the field cannot be found
+ */
+ public static Field getParameterizedField(Class> target, Class> fieldType, Class>... params) {
+ for (Field field : target.getDeclaredFields()) {
+ if (field.getType().equals(fieldType)) {
+ Type type = field.getGenericType();
+ if (type instanceof ParameterizedType) {
+ if (Arrays.equals(((ParameterizedType) type).getActualTypeArguments(), params))
+ return field;
+ }
+ }
+ }
+
+ throw new IllegalArgumentException("Unable to find a field with type " + fieldType + " and params " + Arrays.toString(params));
+ }
+
/**
* Search for the first publicly and privately defined method of the given name and parameter count.
*
@@ -301,6 +328,23 @@ public final class Reflection {
return clazz;
}
+ /**
+ * Retrieve a class from its full name with alternatives, without knowing its type on compile time.
+ *
+ * This is useful when looking up fields by a NMS or OBC type.
+ *
+ *
+ * @see {@link #getClass()} for more information.
+ * @param lookupName - the class name with variables.
+ * @param aliases - alternative names for this class.
+ * @return The class.
+ */
+ public static Class