Search in sources :

Example 1 with HelpTopic

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

the class HelpCommand method execute.

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender))
        return true;
    String command;
    int pageNumber;
    int pageHeight;
    int pageWidth;
    if (args.length == 0) {
        command = "";
        pageNumber = 1;
    } else if (NumberUtils.isDigits(args[args.length - 1])) {
        command = StringUtils.join(ArrayUtils.subarray(args, 0, args.length - 1), " ");
        try {
            pageNumber = NumberUtils.createInteger(args[args.length - 1]);
        } catch (NumberFormatException exception) {
            pageNumber = 1;
        }
        if (pageNumber <= 0) {
            pageNumber = 1;
        }
    } else {
        command = StringUtils.join(args, " ");
        pageNumber = 1;
    }
    if (sender instanceof ConsoleCommandSender) {
        pageHeight = ChatPaginator.UNBOUNDED_PAGE_HEIGHT;
        pageWidth = ChatPaginator.UNBOUNDED_PAGE_WIDTH;
    } else {
        pageHeight = ChatPaginator.CLOSED_CHAT_PAGE_HEIGHT - 1;
        pageWidth = ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH;
    }
    HelpMap helpMap = Bukkit.getServer().getHelpMap();
    HelpTopic topic = helpMap.getHelpTopic(command);
    if (topic == null) {
        topic = helpMap.getHelpTopic("/" + command);
    }
    if (topic == null) {
        topic = findPossibleMatches(command);
    }
    if (topic == null || !topic.canSee(sender)) {
        sender.sendMessage(ChatColor.RED + "No help for " + command);
        return true;
    }
    ChatPaginator.ChatPage page = ChatPaginator.paginate(topic.getFullText(sender), pageNumber, pageWidth, pageHeight);
    StringBuilder header = new StringBuilder();
    header.append(ChatColor.YELLOW);
    header.append("--------- ");
    header.append(ChatColor.WHITE);
    header.append("Help: ");
    header.append(topic.getName());
    header.append(" ");
    if (page.getTotalPages() > 1) {
        header.append("(");
        header.append(page.getPageNumber());
        header.append("/");
        header.append(page.getTotalPages());
        header.append(") ");
    }
    header.append(ChatColor.YELLOW);
    for (int i = header.length(); i < ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH; i++) {
        header.append("-");
    }
    sender.sendMessage(header.toString());
    sender.sendMessage(page.getLines());
    return true;
}
Also used : HelpTopic(org.bukkit.help.HelpTopic) IndexHelpTopic(org.bukkit.help.IndexHelpTopic) HelpMap(org.bukkit.help.HelpMap) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) ChatPaginator(org.bukkit.util.ChatPaginator)

Example 2 with HelpTopic

use of org.bukkit.help.HelpTopic in project Denizen-For-Bukkit by DenizenScript.

the class DenizenAliasHelpTopic method getFullText.

public String getFullText(CommandSender forWho) {
    StringBuilder sb = new StringBuilder(this.shortText);
    HelpTopic aliasForTopic = this.helpMap.getHelpTopic(this.aliasFor);
    if (aliasForTopic != null) {
        sb.append("\n");
        sb.append(aliasForTopic.getFullText(forWho));
    }
    return sb.toString();
}
Also used : HelpTopic(org.bukkit.help.HelpTopic)

Example 3 with HelpTopic

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

the class HelpCommand method tabComplete.

@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");
    if (args.length == 1) {
        List<String> matchedTopics = new ArrayList<String>();
        String searchString = args[0];
        for (HelpTopic topic : Bukkit.getServer().getHelpMap().getHelpTopics()) {
            String trimmedTopic = topic.getName().startsWith("/") ? topic.getName().substring(1) : topic.getName();
            if (trimmedTopic.startsWith(searchString)) {
                matchedTopics.add(trimmedTopic);
            }
        }
        return matchedTopics;
    }
    return ImmutableList.of();
}
Also used : HelpTopic(org.bukkit.help.HelpTopic) IndexHelpTopic(org.bukkit.help.IndexHelpTopic) ArrayList(java.util.ArrayList)

Example 4 with HelpTopic

use of org.bukkit.help.HelpTopic 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

HelpTopic (org.bukkit.help.HelpTopic)4 IndexHelpTopic (org.bukkit.help.IndexHelpTopic)3 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 HelpMap (org.bukkit.help.HelpMap)1 ChatPaginator (org.bukkit.util.ChatPaginator)1