Fix 1_16_R2 bukkit config reload error
- Refactored VersionParam to include patch version specification - Added ConstructorParam to cache constructors & get the default constructor.
This commit is contained in:
parent
f268b098a3
commit
e2a9fb1dc3
9 changed files with 146 additions and 25 deletions
|
|
@ -0,0 +1,14 @@
|
|||
package net.frankheijden.serverutils.common.reflection;
|
||||
|
||||
public class ConstructorParam {
|
||||
|
||||
public final Class<?>[] params;
|
||||
|
||||
private ConstructorParam(Class<?>[] params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
public static ConstructorParam constructorOf(Class<?>... params) {
|
||||
return new ConstructorParam(params);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,8 +3,9 @@ package net.frankheijden.serverutils.common.reflection;
|
|||
import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VERSIONS;
|
||||
|
||||
public class FieldParam {
|
||||
public String field;
|
||||
public VersionParam versionParam;
|
||||
|
||||
public final String field;
|
||||
public final VersionParam versionParam;
|
||||
|
||||
private FieldParam(String field, VersionParam versionParam) {
|
||||
this.field = field;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import static net.frankheijden.serverutils.common.reflection.VersionParam.ALL_VE
|
|||
|
||||
public class MethodParam {
|
||||
|
||||
public String method;
|
||||
public VersionParam versionParam;
|
||||
public Class<?>[] params;
|
||||
public final String method;
|
||||
public final VersionParam versionParam;
|
||||
public final Class<?>[] params;
|
||||
|
||||
private MethodParam(String method, VersionParam versionParam, Class<?>... params) {
|
||||
this.method = method;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
package net.frankheijden.serverutils.common.reflection;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ReflectionUtils {
|
||||
|
|
@ -122,6 +125,24 @@ public abstract class ReflectionUtils {
|
|||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches all constructors by their parameter input.
|
||||
* @param clazz The class to find constructors on.
|
||||
* @param constructorParams The constructor parameters.
|
||||
* @return The list of constructors.
|
||||
*/
|
||||
public static List<Constructor<?>> getAllConstructors(Class<?> clazz, ConstructorParam... constructorParams) {
|
||||
List<Constructor<?>> constructors = new ArrayList<>();
|
||||
for (ConstructorParam constructorParam : constructorParams) {
|
||||
try {
|
||||
constructors.add(clazz.getDeclaredConstructor(constructorParam.params));
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
//
|
||||
}
|
||||
}
|
||||
return constructors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a method on an instance.
|
||||
* Will return null if method not present in map.
|
||||
|
|
|
|||
|
|
@ -2,29 +2,73 @@ package net.frankheijden.serverutils.common.reflection;
|
|||
|
||||
public class VersionParam {
|
||||
|
||||
public static VersionParam ALL_VERSIONS = new VersionParam(Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||
public static final Version MIN_VERSION = new Version(Integer.MIN_VALUE, Integer.MIN_VALUE);
|
||||
public static final Version MAX_VERSION = new Version(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
public static final VersionParam ALL_VERSIONS = new VersionParam(MIN_VERSION, MAX_VERSION);
|
||||
|
||||
public int min;
|
||||
public int max;
|
||||
public final Version min;
|
||||
public final Version max;
|
||||
|
||||
private VersionParam(int min, int max) {
|
||||
this(min, Integer.MIN_VALUE, max, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
private VersionParam(int min, int minPatch, int max, int maxPatch) {
|
||||
this(new Version(min, minPatch), new Version(max, maxPatch));
|
||||
}
|
||||
|
||||
private VersionParam(Version min, Version max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public static VersionParam versionOf(int ver) {
|
||||
public static VersionParam exact(int minor) {
|
||||
return new VersionParam(minor, minor);
|
||||
}
|
||||
|
||||
public static VersionParam exact(Version ver) {
|
||||
return new VersionParam(ver, ver);
|
||||
}
|
||||
|
||||
public static VersionParam between(int min, int max) {
|
||||
public static VersionParam between(int minMinor, int maxMinor) {
|
||||
return new VersionParam(minMinor, maxMinor);
|
||||
}
|
||||
|
||||
public static VersionParam between(Version min, Version max) {
|
||||
return new VersionParam(min, max);
|
||||
}
|
||||
|
||||
public static VersionParam min(int min) {
|
||||
return between(min, Integer.MAX_VALUE);
|
||||
public static VersionParam min(int minMinor) {
|
||||
return between(minMinor, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public static VersionParam max(int max) {
|
||||
return between(Integer.MIN_VALUE, max);
|
||||
public static VersionParam min(Version min) {
|
||||
return between(min, MAX_VERSION);
|
||||
}
|
||||
|
||||
public static VersionParam max(int maxMinor) {
|
||||
return between(Integer.MIN_VALUE, maxMinor);
|
||||
}
|
||||
|
||||
public static VersionParam max(Version max) {
|
||||
return between(MIN_VERSION, max);
|
||||
}
|
||||
|
||||
public static class Version {
|
||||
public final int minor;
|
||||
public final int patch;
|
||||
|
||||
public Version(int minor, int patch) {
|
||||
this.minor = minor;
|
||||
this.patch = patch;
|
||||
}
|
||||
|
||||
public int getMinor() {
|
||||
return minor;
|
||||
}
|
||||
|
||||
public int getPatch() {
|
||||
return patch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue