/** * Override this to control replacements * * @param help * @param entry * @return */ public String[] getEntryFormatReplacements(CommandHelp help, HelpEntry entry) { //{command} {parameters} {separator} {description} return new String[]{ "{command}", entry.getCommand(), "{commandprefix}", help.getCommandPrefix(), "{parameters}", entry.getParameterSyntax(), "{separator}", entry.getDescription().isEmpty() ? "" : "-", "{description}", entry.getDescription() }; }
@UnstableAPI // Not sure on this one yet even when API becomes unstable protected void updateSearchScore(HelpEntry help) { if (this.search == null || this.search.isEmpty()) { help.setSearchScore(1); return; } final RegisteredCommand<?> cmd = help.getRegisteredCommand(); int searchScore = 0; for (String word : this.search) { Pattern pattern = Pattern.compile(".*" + Pattern.quote(word) + ".*", Pattern.CASE_INSENSITIVE); for (String subCmd : cmd.registeredSubcommands) { Pattern subCmdPattern = Pattern.compile(".*" + Pattern.quote(subCmd) + ".*", Pattern.CASE_INSENSITIVE); if (pattern.matcher(subCmd).matches()) { searchScore += 3; } else if (subCmdPattern.matcher(word).matches()) { searchScore++; } } if (pattern.matcher(help.getDescription()).matches()) { searchScore += 2; } if (pattern.matcher(help.getParameterSyntax()).matches()) { searchScore++; } if (help.getSearchTags() != null && pattern.matcher(help.getSearchTags()).matches()) { searchScore += 2; } } help.setSearchScore(searchScore); }
public boolean isExactMatch(String command) { for (HelpEntry helpEntry : helpEntries) { if (helpEntry.getCommand().endsWith(" " + command)) { selectedEntry = helpEntry; return true; } } return false; }
public CommandHelp(CommandManager manager, RootCommand rootCommand, CommandIssuer issuer) { this.manager = manager; this.issuer = issuer; this.perPage = manager.defaultHelpPerPage; this.commandPrefix = manager.getCommandPrefix(issuer); this.commandName = rootCommand.getCommandName(); SetMultimap<String, RegisteredCommand> subCommands = rootCommand.getSubCommands(); Set<RegisteredCommand> seen = new HashSet<>(); if (!rootCommand.getDefCommand().hasHelpCommand) { helpEntries.add(new HelpEntry(this, rootCommand.getDefaultRegisteredCommand())); seen.add(rootCommand.getDefaultRegisteredCommand()); } subCommands.entries().forEach(e -> { String key = e.getKey(); if (key.equals(BaseCommand.DEFAULT) || key.equals(BaseCommand.CATCHUNKNOWN)) { return; } RegisteredCommand regCommand = e.getValue(); if (!regCommand.isPrivate && regCommand.hasPermission(issuer) && !seen.contains(regCommand)) { this.helpEntries.add(new HelpEntry(this, regCommand)); seen.add(regCommand); } }); }
Iterator<HelpEntry> results = helpEntries.stream() .filter(HelpEntry::shouldShow) .sorted(Comparator.comparingInt(helpEntry -> helpEntry.getSearchScore() * -1)).iterator(); if (!results.hasNext()) { issuer.sendMessage(MessageType.ERROR, MessageKeys.NO_COMMAND_MATCHED_SEARCH, "{search}", ACFUtil.join(this.search, " "));
public void showDetailedHelp(CommandHelp commandHelp, HelpEntry entry) { CommandIssuer issuer = commandHelp.getIssuer(); // header printDetailedHelpHeader(commandHelp, issuer, entry); // normal help line printDetailedHelpCommand(commandHelp, issuer, entry); // additionally detailed help for params for (CommandParameter param : entry.getParameters()) { String description = param.getDescription(); if (description != null && !description.isEmpty()) { printDetailedParameter(commandHelp, issuer, entry, param); } } // footer printDetailedHelpFooter(commandHelp, issuer, entry); }
public void printDetailedHelpHeader(CommandHelp help, CommandIssuer issuer, HelpEntry entry) { issuer.sendMessage(MessageType.HELP, MessageKeys.HELP_DETAILED_HEADER, "{command}", entry.getCommand(), "{commandprefix}", help.getCommandPrefix() ); }
/** * Override this to control replacements * * @param help * @param param * @param entry * @return */ @NotNull public String[] getParameterFormatReplacements(CommandHelp help, CommandParameter param, HelpEntry entry) { //{name} {description} return new String[]{ "{name}", param.getName(), "{syntax}", ACFUtil.nullDefault(param.getSyntax(), ""), "{description}", ACFUtil.nullDefault(param.getDescription(), ""), "{command}", help.getCommandName(), "{fullcommand}", entry.getCommand(), "{commandprefix}", help.getCommandPrefix() }; } }