geforkt von Mirrors/FastAsyncWorldEdit
Added a generic injector for commands
Dieser Commit ist enthalten in:
Ursprung
ef60fa94bf
Commit
2af38feadc
23
src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java
Normale Datei
23
src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java
Normale Datei
@ -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;
|
||||
}
|
||||
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren