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;
}
}
Aggregations