use of org.bukkit.command.Command in project NoCheatPlus by NoCheatPlus.
the class CommandUtil method getCommands.
/**
* Get all Command instances, that NCP can get hold of. Attempt to get a SimpleCommandMap instance from the server to get the actually registered commands, but also get commands from JavaPlugin instances.
* @return
*/
public static Collection<Command> getCommands() {
final Collection<Command> commands = new LinkedHashSet<Command>(500);
// All (?) commands from the SimpleCommandMap of the server, if available.
final CommandMap commandMap = getCommandMap();
if (commandMap != null && commandMap instanceof SimpleCommandMap) {
commands.addAll(((SimpleCommandMap) commandMap).getCommands());
}
// Fall-back: plugin commands.
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
if (plugin instanceof JavaPlugin) {
final JavaPlugin javaPlugin = (JavaPlugin) plugin;
final Map<String, Map<String, Object>> map = javaPlugin.getDescription().getCommands();
if (map != null) {
for (String label : map.keySet()) {
Command command = javaPlugin.getCommand(label);
if (command != null) {
commands.add(command);
}
}
}
}
}
return commands;
}
use of org.bukkit.command.Command in project Glowstone by GlowstoneMC.
the class GlowHelpMap method initializeCommands.
/**
* Processes all the commands registered in the server and creates help topics for them.
*/
public synchronized void initializeCommands() {
// Don't load any automatic help topics if All is ignored
if (ignoredPlugins.contains("All")) {
return;
}
Collection<Command> commands = server.getCommandMap().getCommands();
// Initialize help topics from the server's command map
outer: for (Command command : commands) {
if (commandInIgnoredPlugin(command)) {
continue;
}
// Register a topic
for (Entry<Class, HelpTopicFactory<Command>> entry : topicFactoryMap.entrySet()) {
if (((Class<?>) entry.getKey()).isAssignableFrom(command.getClass())) {
HelpTopic t = entry.getValue().createTopic(command);
if (t != null) {
addCommandTopic(t);
}
continue outer;
}
if (command instanceof PluginCommand && ((Class<?>) entry.getKey()).isAssignableFrom(((PluginCommand) command).getExecutor().getClass())) {
HelpTopic t = entry.getValue().createTopic(command);
if (t != null) {
addCommandTopic(t);
}
continue outer;
}
}
addCommandTopic(new GenericCommandHelpTopic(command));
}
// Alias topics for commands
Set<HelpTopic> aliases = new TreeSet<>(TOPIC_COMPARE);
for (Command command : commands) {
if (commandInIgnoredPlugin(command)) {
continue;
}
HelpTopic original = getHelpTopic("/" + command.getLabel());
if (original != null) {
for (String alias : command.getAliases()) {
HelpTopic aliasTopic = new AliasTopic("/" + alias, original);
if (!helpTopics.containsKey(aliasTopic.getName())) {
aliases.add(aliasTopic);
addPrivateTopic(aliasTopic);
}
}
}
}
// Aliases index topic
if (!aliases.isEmpty()) {
addTopic(new IndexHelpTopic("Aliases", "Lists command aliases", null, aliases, null));
}
// Initialize plugin-level sub-topics
Map<String, Set<HelpTopic>> pluginIndexes = new HashMap<>();
for (Command command : commands) {
String pluginName = getCommandPluginName(command);
if (pluginName != null) {
HelpTopic topic = getHelpTopic("/" + command.getLabel());
if (topic != null) {
if (!pluginIndexes.containsKey(pluginName)) {
pluginIndexes.put(pluginName, new TreeSet<>(TOPIC_COMPARE));
}
pluginIndexes.get(pluginName).add(topic);
}
}
}
for (Entry<String, Set<HelpTopic>> entry : pluginIndexes.entrySet()) {
String key = entry.getKey();
addTopic(new IndexHelpTopic(key, "All commands for " + key, null, entry.getValue(), "Below is a list of all " + key + " commands:"));
}
}
Aggregations