+ *
+ * Variable |
+ * Content |
+ *
+ *
+ * {nms} |
+ * Actual package name of net.minecraft.server.VERSION |
+ *
+ *
+ * {obc} |
+ * Actual pacakge name of org.bukkit.craftbukkit.VERSION |
+ *
+ *
+ * {version} |
+ * The current Minecraft package VERSION, if any. |
+ *
+ *
+ *
+ * @param lookupName the class name with variables
+ * @return the looked up class
+ * @throws IllegalArgumentException If a variable or class could not be found
+ */
+ public static Class> getClass(String lookupName) {
+ return getCanonicalClass(expandVariables(lookupName));
+ }
+
+ /**
+ * Search for the first publicly and privately defined constructor of the given name and parameter count.
+ *
+ * @param className lookup name of the class, see {@link #getClass(String)}
+ * @param params the expected parameters
+ * @return an object that invokes this constructor
+ * @throws IllegalStateException If we cannot find this method
+ */
+ public static ConstructorInvoker getConstructor(String className, Class>... params) {
+ return getConstructor(getClass(className), params);
+ }
+
+ /**
+ * Search for the first publicly and privately defined constructor of the given name and parameter count.
+ *
+ * @param clazz a class to start with
+ * @param params the expected parameters
+ * @return an object that invokes this constructor
+ * @throws IllegalStateException If we cannot find this method
+ */
+ public static ConstructorInvoker getConstructor(Class> clazz, Class>... params) {
+ for (final Constructor> constructor : clazz.getDeclaredConstructors()) {
+ if (Arrays.equals(constructor.getParameterTypes(), params)) {
+
+ constructor.setAccessible(true);
+ return new ConstructorInvoker() {
+ @Override
+ public Object invoke(Object... arguments) {
+ try {
+ return constructor.newInstance(arguments);
+ } catch (Exception e) {
+ throw new RuntimeException("Cannot invoke constructor " + constructor, e);
+ }
+ }
+ };
+ }
+ }
+ throw new IllegalStateException(String.format(
+ "Unable to find constructor for %s (%s).", clazz, Arrays.asList(params)));
+ }
+
+ /**
+ * Retrieve a class in the org.bukkit.craftbukkit.VERSION.* package.
+ *
+ * @param name the name of the class, excluding the package
+ * @throws IllegalArgumentException If the class doesn't exist
+ */
+ public static Class> getCraftBukkitClass(String name) {
+ return getCanonicalClass(OBC_PREFIX + "." + name);
+ }
+
+ /**
+ * Retrieve a field accessor for a specific field type and name.
+ *
+ * @param target the target type
+ * @param name the name of the field, or NULL to ignore
+ * @param fieldType a compatible field type
+ * @return the field accessor
+ */
+ public static