13
0
geforkt von Mirrors/Paper

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

Dieser Commit ist enthalten in:
rmichela 2012-03-14 23:39:19 -04:00 committet von EvilSeph
Ursprung fc697a4f44
Commit 184faf1f29
4 geänderte Dateien mit 63 neuen und 17 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -2,10 +2,12 @@ package org.bukkit.craftbukkit.help;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.Collections2; import com.google.common.collect.Collections2;
import org.bukkit.Server;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.MultipleCommandAlias; import org.bukkit.command.MultipleCommandAlias;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.command.defaults.VanillaCommand; import org.bukkit.command.defaults.VanillaCommand;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.help.*; import org.bukkit.help.*;
@ -19,12 +21,14 @@ public class SimpleHelpMap implements HelpMap {
private HelpTopic defaultTopic; private HelpTopic defaultTopic;
private Map<String, HelpTopic> helpTopics; 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 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)))); 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()); registerHelpTopicFactory(MultipleCommandAlias.class, new MultipleCommandAliasHelpTopicFactory());
} }
@ -52,11 +56,14 @@ public class SimpleHelpMap implements HelpMap {
helpTopics.clear(); 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. * 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); HelpYamlReader reader = new HelpYamlReader(server);
// Initialize general help topics from the help.yml file // 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. * 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() {
public synchronized void initializeCommands(CraftServer server) {
// ** Load topics from highest to lowest priority order ** // ** 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 // Initialize help topics from the server's command map
outer: for (Command command : server.getCommandMap().getCommands()) { outer: for (Command command : server.getCommandMap().getCommands()) {
if (commandInIgnoredPlugin(command, ignoredPlugins)) {
continue outer;
}
// Register a topic
for (Class c : topicFactoryMap.keySet()) { for (Class c : topicFactoryMap.keySet()) {
if (c.isAssignableFrom(command.getClass())) { if (c.isAssignableFrom(command.getClass())) {
addTopic(topicFactoryMap.get(c).createTopic(command)); addTopic(topicFactoryMap.get(c).createTopic(command));
@ -90,6 +102,9 @@ public class SimpleHelpMap implements HelpMap {
// Initialize command alias help topics // Initialize command alias help topics
for (Command command : server.getCommandMap().getCommands()) { for (Command command : server.getCommandMap().getCommands()) {
if (commandInIgnoredPlugin(command, ignoredPlugins)) {
continue;
}
for (String alias : command.getAliases()) { for (String alias : command.getAliases()) {
addTopic(new CommandAliasHelpTopic(alias, command.getLabel(), this)); 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 // Initialize help topics from the server's fallback commands
for (VanillaCommand command : server.getCommandMap().getFallbackCommands()) { for (VanillaCommand command : server.getCommandMap().getFallbackCommands()) {
addTopic(new GenericCommandHelpTopic(command)); if (!commandInIgnoredPlugin(command, ignoredPlugins)) {
addTopic(new GenericCommandHelpTopic(command));
}
} }
// Add alias sub-index // Add alias sub-index
addTopic(new IndexHelpTopic("Aliases", "Lists command aliases", null, Collections2.filter(helpTopics.values(), Predicates.instanceOf(CommandAliasHelpTopic.class)))); addTopic(new IndexHelpTopic("Aliases", "Lists command aliases", null, Collections2.filter(helpTopics.values(), Predicates.instanceOf(CommandAliasHelpTopic.class))));
// Amend help topics from the help.yml file // Amend help topics from the help.yml file
HelpYamlReader reader = new HelpYamlReader(server); for (HelpTopicAmendment amendment : helpYamlReader.getTopicAmendments()) {
for (HelpTopicAmendment amendment : reader.getTopicAmendments()) {
if (helpTopics.containsKey(amendment.getTopicName())) { if (helpTopics.containsKey(amendment.getTopicName())) {
helpTopics.get(amendment.getTopicName()).amendTopic(amendment.getShortText(), amendment.getFullText()); helpTopics.get(amendment.getTopicName()).amendTopic(amendment.getShortText(), amendment.getFullText());
if (amendment.getPermission() != null) { if (amendment.getPermission() != null) {
@ -114,6 +130,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) { public void registerHelpTopicFactory(Class commandClass, HelpTopicFactory factory) {
if (!Command.class.isAssignableFrom(commandClass) && !CommandExecutor.class.isAssignableFrom(commandClass)) { if (!Command.class.isAssignableFrom(commandClass) && !CommandExecutor.class.isAssignableFrom(commandClass)) {

Datei anzeigen

@ -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 # 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. # 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. # This file is divided up into the following parts:
# Color codes are allowed. When amending command topic, the string <text> will be replaced with the existing value # -- general-topics: lists admin defined topics
# in the help topic. # -- 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: # general-topics:
# rules: # rules:
# shortText: Rules of the server # shortText: Rules of the server
@ -16,8 +21,16 @@
# 3. No swearing. # 3. No swearing.
# permission: topics.rules # permission: topics.rules
# -- # --
# Topic amendments are used to change the content of automatically generated plugin command topics.
# amended-topics: # amended-topics:
# /stop: # /stop:
# shortText: Stops the server cold....in its tracks! # shortText: Stops the server cold....in its tracks!
# fullText: <text> - This kills the server. # fullText: <text> - This kills the server.
# permission: you.dont.have # 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