Added a generic injector for commands

This commit is contained in:
zml2008 2011-08-23 21:31:17 -07:00
parent ef60fa94bf
commit 2af38feadc

View File

@ -0,0 +1,23 @@
package com.sk89q.minecraft.util.commands;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
public class SimpleInjector<T> implements Injector {
private final T injectionObject;
public SimpleInjector(T injectionObject) {
this.injectionObject = injectionObject;
}
public Object getInstance(Class<?> cls) throws InvocationTargetException,
IllegalAccessException, InstantiationException {
try {
Constructor<?> construct = cls.getConstructor(injectionObject.getClass());
return construct.newInstance(injectionObject);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
return null;
}
}