private String createUsage(Method method) { MCCommand cmd = method.getAnnotation(MCCommand.class); List<String> str = new ArrayList<String>(); String thecmd = cmd.cmds().length > 0 ? cmd.cmds()[0] : ""; String thesubcmd = cmd.subCmds().length > 0 ? cmd.subCmds()[0] : null; Class<?> types[] = method.getParameterTypes(); if (commandIndex == 0) { str.add(thecmd); if (thesubcmd != null) { str.add(thesubcmd); } } for (int i = 1; i < types.length; i++) { Class<?> theclass = types[i]; str.add(getUsageString(theclass)); if (i == commandIndex) { str.add(thecmd); if (thesubcmd != null) { str.add(thesubcmd); } } } return StringUtils.join(str, " "); }
private String createUsage(Method method) { MCCommand cmd = method.getAnnotation(MCCommand.class); StringBuilder sb = new StringBuilder(cmd.cmds().length > 0 ? cmd.cmds()[0] + " " : ""); int startIndex = 1; if (cmd.subCmds().length > 0) { sb.append(cmd.subCmds()[0] + " "); startIndex = 2; } Class<?> types[] = method.getParameterTypes(); for (int i = startIndex; i < types.length; i++) { Class<?> theclass = types[i]; sb.append(getUsageString(theclass)); } return sb.toString(); }
public void addMethods(Object obj, Method[] methodArray) { for (Method method : methodArray) { MCCommand mc = method.getAnnotation(MCCommand.class); if (mc == null) continue; Class<?> types[] = method.getParameterTypes(); if (types.length == 0 || !validCommandSenderClass(types[0])) { System.err.println("MCCommands must start with a CommandSender,Player, or ArenaPlayer"); continue; } if (mc.cmds().length == 0) { /// There is no subcommand. just the command itself with arguments addMethod(obj, method, mc, DEFAULT_CMD); } else { /// For each of the cmds, store them with the method for (String cmd : mc.cmds()) { addMethod(obj, method, mc, cmd.toLowerCase()); } } } }