Search in sources :

Example 1 with IndexHelpTopic

use of org.bukkit.help.IndexHelpTopic in project Bukkit by Bukkit.

the class HelpCommand method findPossibleMatches.

protected HelpTopic findPossibleMatches(String searchString) {
    int maxDistance = (searchString.length() / 5) + 3;
    Set<HelpTopic> possibleMatches = new TreeSet<HelpTopic>(HelpTopicComparator.helpTopicComparatorInstance());
    if (searchString.startsWith("/")) {
        searchString = searchString.substring(1);
    }
    for (HelpTopic topic : Bukkit.getServer().getHelpMap().getHelpTopics()) {
        String trimmedTopic = topic.getName().startsWith("/") ? topic.getName().substring(1) : topic.getName();
        if (trimmedTopic.length() < searchString.length()) {
            continue;
        }
        if (Character.toLowerCase(trimmedTopic.charAt(0)) != Character.toLowerCase(searchString.charAt(0))) {
            continue;
        }
        if (damerauLevenshteinDistance(searchString, trimmedTopic.substring(0, searchString.length())) < maxDistance) {
            possibleMatches.add(topic);
        }
    }
    if (possibleMatches.size() > 0) {
        return new IndexHelpTopic("Search", null, null, possibleMatches, "Search for: " + searchString);
    } else {
        return null;
    }
}
Also used : TreeSet(java.util.TreeSet) HelpTopic(org.bukkit.help.HelpTopic) IndexHelpTopic(org.bukkit.help.IndexHelpTopic) IndexHelpTopic(org.bukkit.help.IndexHelpTopic)

Aggregations

TreeSet (java.util.TreeSet)1 HelpTopic (org.bukkit.help.HelpTopic)1 IndexHelpTopic (org.bukkit.help.IndexHelpTopic)1