Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
PluginsCommand.java
1 package org.bukkit.command.defaults;
2 
3 import java.util.Arrays;
4 
5 import org.bukkit.Bukkit;
6 import org.bukkit.ChatColor;
8 import org.bukkit.plugin.Plugin;
9 
10 public class PluginsCommand extends BukkitCommand {
11  public PluginsCommand(String name) {
12  super(name);
13  this.description = "Gets a list of plugins running on the server";
14  this.usageMessage = "/plugins";
15  this.setPermission("bukkit.command.plugins");
16  this.setAliases(Arrays.asList("pl"));
17  }
18 
19  @Override
20  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
21  if (!testPermission(sender)) return true;
22 
23  sender.sendMessage("Plugins " + getPluginList());
24  return true;
25  }
26 
27  private String getPluginList() {
28  StringBuilder pluginList = new StringBuilder();
29  Plugin[] plugins = Bukkit.getPluginManager().getPlugins();
30 
31  for (Plugin plugin : plugins) {
32  if (pluginList.length() > 0) {
33  pluginList.append(ChatColor.WHITE);
34  pluginList.append(", ");
35  }
36 
37  pluginList.append(plugin.isEnabled() ? ChatColor.GREEN : ChatColor.RED);
38  pluginList.append(plugin.getDescription().getName());
39  }
40 
41  return "(" + plugins.length + "): " + pluginList.toString();
42  }
43 }
boolean testPermission(CommandSender target)
Command setAliases(List< String > aliases)
void sendMessage(String message)
void setPermission(String permission)
static PluginManager getPluginManager()
Definition: Bukkit.java:208