org.bukkit.help.HelpTopic Java Examples

The following examples show how to use org.bukkit.help.HelpTopic. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HelpCommand.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@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();
}
 
Example #2
Source File: CustomIndexHelpTopic.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String getFullText(CommandSender sender) {
    if (futureTopics != null) {
        List<HelpTopic> topics = new LinkedList<HelpTopic>();
        for (String futureTopic : futureTopics) {
            HelpTopic topic = helpMap.getHelpTopic(futureTopic);
            if (topic != null) {
                topics.add(topic);
            }
        }
        setTopicsCollection(topics);
        futureTopics = null;
    }

    return super.getFullText(sender);
}
 
Example #3
Source File: HelpYamlReader.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Extracts a list of all index topics from help.yml
 *
 * @return A list of index topics.
 */
public List<HelpTopic> getIndexTopics() {
    List<HelpTopic> topics = new LinkedList<HelpTopic>();
    ConfigurationSection indexTopics = helpYaml.getConfigurationSection("index-topics");
    if (indexTopics != null) {
        for (String topicName : indexTopics.getKeys(false)) {
            ConfigurationSection section = indexTopics.getConfigurationSection(topicName);
            String shortText = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("shortText", ""));
            String preamble = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("preamble", ""));
            String permission = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("permission", ""));
            List<String> commands = section.getStringList("commands");
            topics.add(new CustomIndexHelpTopic(server.getHelpMap(), topicName, shortText, permission, commands, preamble));
        }
    }
    return topics;
}
 
Example #4
Source File: HelpYamlReader.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Extracts a list of all index topics from help.yml
 *
 * @return A list of index topics.
 */
public List<HelpTopic> getIndexTopics() {
    List<HelpTopic> topics = new LinkedList<HelpTopic>();
    ConfigurationSection indexTopics = helpYaml.getConfigurationSection("index-topics");
    if (indexTopics != null) {
        for (String topicName : indexTopics.getKeys(false)) {
            ConfigurationSection section = indexTopics.getConfigurationSection(topicName);
            String shortText = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("shortText", ""));
            String preamble = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("preamble", ""));
            String permission = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("permission", ""));
            List<String> commands = section.getStringList("commands");
            topics.add(new CustomIndexHelpTopic(server.getHelpMap(), topicName, shortText, permission, commands, preamble));
        }
    }
    return topics;
}
 
Example #5
Source File: CustomIndexHelpTopic.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String getFullText(CommandSender sender) {
    if (futureTopics != null) {
        List<HelpTopic> topics = new LinkedList<HelpTopic>();
        for (String futureTopic : futureTopics) {
            HelpTopic topic = helpMap.getHelpTopic(futureTopic);
            if (topic != null) {
                topics.add(topic);
            }
        }
        setTopicsCollection(topics);
        futureTopics = null;
    }

    return super.getFullText(sender);
}
 
Example #6
Source File: ScriptCommand.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
public void unregisterHelp() {
	Bukkit.getHelpMap().getHelpTopics().removeAll(helps);
	final HelpTopic aliases = Bukkit.getHelpMap().getHelpTopic("Aliases");
	if (aliases != null && aliases instanceof IndexHelpTopic) {
		try {
			final Field topics = IndexHelpTopic.class.getDeclaredField("allTopics");
			topics.setAccessible(true);
			@SuppressWarnings("unchecked")
			final ArrayList<HelpTopic> as = new ArrayList<>((Collection<HelpTopic>) topics.get(aliases));
			as.removeAll(helps);
			topics.set(aliases, as);
		} catch (final Exception e) {
			Skript.outdatedError(e);//, "error unregistering aliases for /" + getName());
		}
	}
	helps.clear();
}
 
Example #7
Source File: ScriptCommand.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
public void registerHelp() {
	helps.clear();
	final HelpMap help = Bukkit.getHelpMap();
	final HelpTopic t = new GenericCommandHelpTopic(bukkitCommand);
	help.addTopic(t);
	helps.add(t);
	final HelpTopic aliases = help.getHelpTopic("Aliases");
	if (aliases instanceof IndexHelpTopic) {
		aliases.getFullText(Bukkit.getConsoleSender()); // CraftBukkit has a lazy IndexHelpTopic class (org.bukkit.craftbukkit.help.CustomIndexHelpTopic) - maybe its used for aliases as well
		try {
			final Field topics = IndexHelpTopic.class.getDeclaredField("allTopics");
			topics.setAccessible(true);
			@SuppressWarnings("unchecked")
			final ArrayList<HelpTopic> as = new ArrayList<>((Collection<HelpTopic>) topics.get(aliases));
			for (final String alias : activeAliases) {
				final HelpTopic at = new CommandAliasHelpTopic("/" + alias, "/" + getLabel(), help);
				as.add(at);
				helps.add(at);
			}
			Collections.sort(as, HelpTopicComparator.helpTopicComparatorInstance());
			topics.set(aliases, as);
		} catch (final Exception e) {
			Skript.outdatedError(e);//, "error registering aliases for /" + getName());
		}
	}
}
 
Example #8
Source File: CommandAliasHelpTopic.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean canSee(CommandSender commandSender) {
    if (amendedPermission == null) {
        HelpTopic aliasForTopic = helpMap.getHelpTopic(aliasFor);
        if (aliasForTopic != null) {
            return aliasForTopic.canSee(commandSender);
        } else {
            return false;
        }
    } else {
        return commandSender.hasPermission(amendedPermission);
    }
}
 
Example #9
Source File: CommandAliasHelpTopic.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getFullText(CommandSender forWho) {
    StringBuilder sb = new StringBuilder(shortText);
    HelpTopic aliasForTopic = helpMap.getHelpTopic(aliasFor);
    if (aliasForTopic != null) {
        sb.append("\n");
        sb.append(aliasForTopic.getFullText(forWho));
    }
    return sb.toString();
}
 
Example #10
Source File: HelpYamlReader.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Extracts a list of all general help topics from help.yml
 *
 * @return A list of general topics.
 */
public List<HelpTopic> getGeneralTopics() {
    List<HelpTopic> topics = new LinkedList<HelpTopic>();
    ConfigurationSection generalTopics = helpYaml.getConfigurationSection("general-topics");
    if (generalTopics != null) {
        for (String topicName : generalTopics.getKeys(false)) {
            ConfigurationSection section = generalTopics.getConfigurationSection(topicName);
            String shortText = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("shortText", ""));
            String fullText = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("fullText", ""));
            String permission = section.getString("permission", "");
            topics.add(new CustomHelpTopic(topicName, shortText, fullText, permission));
        }
    }
    return topics;
}
 
Example #11
Source File: Commands.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getFullText(final CommandSender forWho) {
	final StringBuilder sb = new StringBuilder(shortText);
	final HelpTopic aliasForTopic = helpMap.getHelpTopic(aliasFor);
	if (aliasForTopic != null) {
		sb.append("\n");
		sb.append(aliasForTopic.getFullText(forWho));
	}
	return "" + sb.toString();
}
 
Example #12
Source File: CommandAliasHelpTopic.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean canSee(CommandSender commandSender) {
    if (amendedPermission == null) {
        HelpTopic aliasForTopic = helpMap.getHelpTopic(aliasFor);
        if (aliasForTopic != null) {
            return aliasForTopic.canSee(commandSender);
        } else {
            return false;
        }
    } else {
        return commandSender.hasPermission(amendedPermission);
    }
}
 
Example #13
Source File: CommandAliasHelpTopic.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getFullText(CommandSender forWho) {
    StringBuilder sb = new StringBuilder(shortText);
    HelpTopic aliasForTopic = helpMap.getHelpTopic(aliasFor);
    if (aliasForTopic != null) {
        sb.append("\n");
        sb.append(aliasForTopic.getFullText(forWho));
    }
    return sb.toString();
}
 
Example #14
Source File: HelpYamlReader.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Extracts a list of all general help topics from help.yml
 *
 * @return A list of general topics.
 */
public List<HelpTopic> getGeneralTopics() {
    List<HelpTopic> topics = new LinkedList<HelpTopic>();
    ConfigurationSection generalTopics = helpYaml.getConfigurationSection("general-topics");
    if (generalTopics != null) {
        for (String topicName : generalTopics.getKeys(false)) {
            ConfigurationSection section = generalTopics.getConfigurationSection(topicName);
            String shortText = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("shortText", ""));
            String fullText = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("fullText", ""));
            String permission = section.getString("permission", "");
            topics.add(new CustomHelpTopic(topicName, shortText, fullText, permission));
        }
    }
    return topics;
}
 
Example #15
Source File: HelpCommand.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
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;
    }
}
 
Example #16
Source File: BukkitHelpTopic.java    From intake with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public HelpTopic createTopic(BukkitCommand command) {
  return new BukkitHelpTopic(command);
}
 
Example #17
Source File: CustomIndexHelpTopic.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public CustomIndexHelpTopic(HelpMap helpMap, String name, String shortText, String permission, List<String> futureTopics, String preamble) {
    super(name, shortText, permission, new HashSet<HelpTopic>(), preamble);
    this.helpMap = helpMap;
    this.futureTopics = futureTopics;
}
 
Example #18
Source File: MultipleCommandAliasHelpTopicFactory.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public HelpTopic createTopic(MultipleCommandAlias multipleCommandAlias) {
    return new MultipleCommandAliasHelpTopic(multipleCommandAlias);
}
 
Example #19
Source File: MultipleCommandAliasHelpTopicFactory.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
public HelpTopic createTopic(MultipleCommandAlias multipleCommandAlias) {
    return new MultipleCommandAliasHelpTopic(multipleCommandAlias);
}
 
Example #20
Source File: CustomIndexHelpTopic.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
public CustomIndexHelpTopic(HelpMap helpMap, String name, String shortText, String permission, List<String> futureTopics, String preamble) {
    super(name, shortText, permission, new HashSet<HelpTopic>(), preamble);
    this.helpMap = helpMap;
    this.futureTopics = futureTopics;
}
 
Example #21
Source File: HelpCommand.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@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;
}