private boolean methodRegistration( Named owner, Class<?> commands, Object instance, org.spout.api.command.Command parent) { boolean success = true; for (Method method : commands.getDeclaredMethods()) { // Basic checks method.setAccessible(true); if (!Modifier.isStatic(method.getModifiers()) && instance == null) { continue; } org.spout.api.command.Command child = createCommand(owner, parent, method); if (child == null) { continue; } if (method.isAnnotationPresent(NestedCommand.class)) { for (Class<?> clazz : method.getAnnotation(NestedCommand.class).value()) { success &= create(owner, clazz, child); } } else { child.setExecutor(executorFactory.getAnnotatedCommandExecutor(instance, method)); } child.closeSubCommand(); } return success; }
private boolean nestedClassRegistration( Named owner, Class<?> commands, Object instance, org.spout.api.command.Command parent) { boolean success = true, anyRegistered = false; for (Class<?> clazz : commands.getDeclaredClasses()) { Object subInstance = null; if (!Modifier.isStatic(clazz.getModifiers())) { try { Constructor<?> constr = getClosestConstructor(clazz, commands); if (constr == null) { continue; } constr.setAccessible(true); subInstance = constr.newInstance(instance); } catch (InvocationTargetException e) { e.printStackTrace(); continue; } catch (InstantiationException e) { e.printStackTrace(); continue; } catch (IllegalAccessException ignore) { } } org.spout.api.command.Command child = createCommand(owner, parent, clazz); if (child == null) { continue; } anyRegistered = true; if (!nestedClassRegistration(owner, clazz, subInstance, child)) { for (Method method : clazz.getDeclaredMethods()) { if (!method.isAnnotationPresent(Executor.class)) { continue; } Platform platform = method.getAnnotation(Executor.class).value(); child.setExecutor( platform, executorFactory.getAnnotatedCommandExecutor(subInstance, method)); } } } return success && anyRegistered; }