001 package org.bukkit.command.defaults; 002 003 import java.util.Arrays; 004 005 import org.bukkit.Bukkit; 006 import org.bukkit.ChatColor; 007 import org.bukkit.command.CommandSender; 008 import org.bukkit.plugin.Plugin; 009 010 public class PluginsCommand extends BukkitCommand { 011 public PluginsCommand(String name) { 012 super(name); 013 this.description = "Gets a list of plugins running on the server"; 014 this.usageMessage = "/plugins"; 015 this.setPermission("bukkit.command.plugins"); 016 this.setAliases(Arrays.asList("pl")); 017 } 018 019 @Override 020 public boolean execute(CommandSender sender, String currentAlias, String[] args) { 021 if (!testPermission(sender)) return true; 022 023 sender.sendMessage("Plugins " + getPluginList()); 024 return true; 025 } 026 027 private String getPluginList() { 028 StringBuilder pluginList = new StringBuilder(); 029 Plugin[] plugins = Bukkit.getPluginManager().getPlugins(); 030 031 for (Plugin plugin : plugins) { 032 if (pluginList.length() > 0) { 033 pluginList.append(ChatColor.WHITE); 034 pluginList.append(", "); 035 } 036 037 pluginList.append(plugin.isEnabled() ? ChatColor.GREEN : ChatColor.RED); 038 pluginList.append(plugin.getDescription().getName()); 039 } 040 041 return "(" + plugins.length + "): " + pluginList.toString(); 042 } 043 }