mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-26 09:34:27 +00:00
Added more flexibility to the Bukkit dynamic command registration system.
This commit is contained in:
@ -20,8 +20,10 @@ package com.sk89q.minecraft.util.commands;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class SimpleInjector implements Injector {
|
||||
private static final Logger logger = Logger.getLogger(SimpleInjector.class.getCanonicalName());
|
||||
private Object[] args;
|
||||
private Class<?>[] argClasses;
|
||||
|
||||
@ -36,14 +38,23 @@ public class SimpleInjector implements Injector {
|
||||
public Object getInstance(Class<?> clazz) {
|
||||
try {
|
||||
Constructor<?> ctr = clazz.getConstructor(argClasses);
|
||||
ctr.setAccessible(true);
|
||||
return ctr.newInstance(args);
|
||||
} catch (NoSuchMethodException e) {
|
||||
logger.severe("Error initializing commands class " + clazz + ": ");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (InvocationTargetException e) {
|
||||
logger.severe("Error initializing commands class " + clazz + ": ");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (InstantiationException e) {
|
||||
logger.severe("Error initializing commands class " + clazz + ": ");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.severe("Error initializing commands class " + clazz + ": ");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user