[Bleeding] Added option to remove entire plugins from the help index using the help.yml file. Addresses BUKKIT-1178

This commit is contained in:
rmichela 2012-03-14 23:39:19 -04:00 committed by EvilSeph
parent fc697a4f44
commit 184faf1f29
4 changed files with 63 additions and 17 deletions

View File

@ -129,7 +129,7 @@ public final class CraftServer implements Server {
private final ServicesManager servicesManager = new SimpleServicesManager();
private final BukkitScheduler scheduler = new CraftScheduler();
private final SimpleCommandMap commandMap = new SimpleCommandMap(this);
private final SimpleHelpMap helpMap = new SimpleHelpMap();
private final SimpleHelpMap helpMap = new SimpleHelpMap(this);
private final StandardMessenger messenger = new StandardMessenger();
private final PluginManager pluginManager = new SimplePluginManager(this, commandMap);
protected final MinecraftServer console;
@ -222,7 +222,7 @@ public final class CraftServer implements Server {
public void enablePlugins(PluginLoadOrder type) {
if (type == PluginLoadOrder.STARTUP) {
helpMap.clear();
helpMap.initializeGeneralTopics(this);
helpMap.initializeGeneralTopics();
}
Plugin[] plugins = pluginManager.getPlugins();
@ -237,7 +237,7 @@ public final class CraftServer implements Server {
commandMap.registerServerAliases();
loadCustomPermissions();
DefaultPermissions.registerCorePermissions();
helpMap.initializeCommands(this);
helpMap.initializeCommands();
}
}

View File

@ -70,4 +70,8 @@ public class HelpYamlReader {
}
return amendments;
}
public List<String> getIgnoredPlugins() {
return helpYaml.getStringList("ignore-plugins");
}
}

View File

@ -2,10 +2,12 @@ package org.bukkit.craftbukkit.help;
import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.MultipleCommandAlias;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.command.defaults.VanillaCommand;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.help.*;
@ -19,12 +21,14 @@ public class SimpleHelpMap implements HelpMap {
private HelpTopic defaultTopic;
private Map<String, HelpTopic> helpTopics;
private Map<Class, HelpTopicFactory> topicFactoryMap;
private Map<Class, HelpTopicFactory<Command>> topicFactoryMap;
private CraftServer server;
public SimpleHelpMap() {
public SimpleHelpMap(CraftServer server) {
helpTopics = new TreeMap<String, HelpTopic>(new HelpTopicComparator()); // Using a TreeMap for its explicit sorting on key
defaultTopic = new IndexHelpTopic("Index", null, null, Collections2.filter(helpTopics.values(), Predicates.not(Predicates.instanceOf(CommandAliasHelpTopic.class))));
topicFactoryMap = new HashMap<Class, HelpTopicFactory>();
topicFactoryMap = new HashMap<Class, HelpTopicFactory<Command>>();
this.server = server;
registerHelpTopicFactory(MultipleCommandAlias.class, new MultipleCommandAliasHelpTopicFactory());
}
@ -52,11 +56,14 @@ public class SimpleHelpMap implements HelpMap {
helpTopics.clear();
}
public List<String> getIgnoredPlugins() {
return new HelpYamlReader(server).getIgnoredPlugins();
}
/**
* Reads the general topics from help.yml and adds them to the help index.
* @param server A reference to the server.
*/
public synchronized void initializeGeneralTopics(CraftServer server) {
public synchronized void initializeGeneralTopics() {
HelpYamlReader reader = new HelpYamlReader(server);
// Initialize general help topics from the help.yml file
@ -67,14 +74,19 @@ public class SimpleHelpMap implements HelpMap {
/**
* Processes all the commands registered in the server and creates help topics for them.
* @param server A reference to the server.
*/
@SuppressWarnings("unchecked")
public synchronized void initializeCommands(CraftServer server) {
public synchronized void initializeCommands() {
// ** Load topics from highest to lowest priority order **
HelpYamlReader helpYamlReader = new HelpYamlReader(server);
List<String> ignoredPlugins = helpYamlReader.getIgnoredPlugins();
// Initialize help topics from the server's command map
outer: for (Command command : server.getCommandMap().getCommands()) {
if (commandInIgnoredPlugin(command, ignoredPlugins)) {
continue outer;
}
// Register a topic
for (Class c : topicFactoryMap.keySet()) {
if (c.isAssignableFrom(command.getClass())) {
addTopic(topicFactoryMap.get(c).createTopic(command));
@ -90,6 +102,9 @@ public class SimpleHelpMap implements HelpMap {
// Initialize command alias help topics
for (Command command : server.getCommandMap().getCommands()) {
if (commandInIgnoredPlugin(command, ignoredPlugins)) {
continue;
}
for (String alias : command.getAliases()) {
addTopic(new CommandAliasHelpTopic(alias, command.getLabel(), this));
}
@ -97,15 +112,16 @@ public class SimpleHelpMap implements HelpMap {
// Initialize help topics from the server's fallback commands
for (VanillaCommand command : server.getCommandMap().getFallbackCommands()) {
if (!commandInIgnoredPlugin(command, ignoredPlugins)) {
addTopic(new GenericCommandHelpTopic(command));
}
}
// Add alias sub-index
addTopic(new IndexHelpTopic("Aliases", "Lists command aliases", null, Collections2.filter(helpTopics.values(), Predicates.instanceOf(CommandAliasHelpTopic.class))));
// Amend help topics from the help.yml file
HelpYamlReader reader = new HelpYamlReader(server);
for (HelpTopicAmendment amendment : reader.getTopicAmendments()) {
for (HelpTopicAmendment amendment : helpYamlReader.getTopicAmendments()) {
if (helpTopics.containsKey(amendment.getTopicName())) {
helpTopics.get(amendment.getTopicName()).amendTopic(amendment.getShortText(), amendment.getFullText());
if (amendment.getPermission() != null) {
@ -115,6 +131,19 @@ public class SimpleHelpMap implements HelpMap {
}
}
private boolean commandInIgnoredPlugin(Command command, List<String> ignoredPlugins) {
if (command instanceof BukkitCommand && ignoredPlugins.contains("Bukkit")) {
return true;
}
if (command instanceof VanillaCommand && ignoredPlugins.contains("Bukkit")) {
return true;
}
if (command instanceof PluginCommand && ignoredPlugins.contains(((PluginCommand)command).getPlugin().getName())) {
return true;
}
return false;
}
public void registerHelpTopicFactory(Class commandClass, HelpTopicFactory factory) {
if (!Command.class.isAssignableFrom(commandClass) && !CommandExecutor.class.isAssignableFrom(commandClass)) {
throw new IllegalArgumentException("commandClass must implement either Command or CommandExecutor!");

View File

@ -3,10 +3,15 @@
# or extracted from your installed plugins. You only need to modify this file if you wish to add new help pages to
# your server or override the help pages of existing plugin commands.
# --
# This file is divided up into two parts: general-topics and command-topics respectively. Examples are given below.
# Color codes are allowed. When amending command topic, the string <text> will be replaced with the existing value
# in the help topic.
# This file is divided up into the following parts:
# -- general-topics: lists admin defined topics
# -- amend-topics: lists topic amendments to apply to existing help topics
# -- ignore-plugins: lists any plugins that should be excluded from help
# general-topics and command-topics respectively.
# Examples are given below. Color codes are allowed. When amending command topic, the string <text> will be replaced
# with the existing value in the help topic.
# --
# Each general topic will show up as a separate topic in the help index along with all the plugin command topics.
# general-topics:
# rules:
# shortText: Rules of the server
@ -16,8 +21,16 @@
# 3. No swearing.
# permission: topics.rules
# --
# Topic amendments are used to change the content of automatically generated plugin command topics.
# amended-topics:
# /stop:
# shortText: Stops the server cold....in its tracks!
# fullText: <text> - This kills the server.
# permission: you.dont.have
# --
# Any plugin in the ignored plugins list will be excluded from help. The name must match the name displayed by
# the /plugins command. Ignore "Bukkit" to remove the standard bukkit commands from the index.
# ignore-plugins:
# - PluginNameOne
# - PluginNameTwo
# - PluginNameThree