public boolean registerAll(List<Command> registered) { List<CommandInfo> toRegister = new ArrayList<>(); for (Command command : registered) { List<String> permissions = null; Method cmdMethod = commands.getMethods().get(null).get(command.aliases()[0]); Map<String, Method> childMethods = commands.getMethods().get(cmdMethod); if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) { permissions = Arrays.asList(cmdMethod.getAnnotation(CommandPermissions.class).value()); } else if (cmdMethod != null && childMethods != null && !childMethods.isEmpty()) { permissions = new ArrayList<>(); for (Method m : childMethods.values()) { if (m.isAnnotationPresent(CommandPermissions.class)) { permissions.addAll(Arrays.asList(m.getAnnotation(CommandPermissions.class).value())); } } } toRegister.add(new CommandInfo(command.usage(), command.desc(), command.aliases(), commands, permissions == null ? null : permissions.toArray(new String[permissions.size()]))); } return register(toRegister); }
public boolean registerAll(List<Command> registered) { List<CommandInfo> toRegister = new ArrayList<CommandInfo>(); for (Command command : registered) { String[] permissions = null; Method cmdMethod = commands.getMethods().get(null).get(command.aliases()[0]); if(cmdMethod != null) { if(cmdMethod.isAnnotationPresent(CommandPermissions.class)) { permissions = cmdMethod.getAnnotation(CommandPermissions.class).value(); } } toRegister.add(new CommandInfo(command.usage(), command.desc(), command.aliases(), commands, permissions)); } return register(toRegister); } }