Solved Getting the plugins list

Discussion in 'Plugin Development' started by random_username, Oct 22, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    random_username

    Hello, i am trying to make a command for my plugin to get a plugins list. I know I could do /pl or /plugins but I'm using those commands for other messages... So this is what I'm trying:
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender Sender, Command cmd, String commandLabel, String[] args){
    3. PluginManager pm = this.getServer().getPluginManager();
    4. //some not important stuff here
    5. else if(cmd.getName().equalsIgnoreCase("core")){
    6. if(Sender.hasPermission("ecore.admin")){
    7. if(args.length == 0){
    8. Sender.sendMessage(getConfig().getString("Prefix").replace("&", "§") + "Not enough arguments!");
    9. }if(args.length == 1 && args[0].equalsIgnoreCase("reload")){
    10. reloadConfig();
    11. Sender.sendMessage(getConfig().getString("Prefix").replace("&", "§") + getConfig().getString("rl").replace("&", "§"));
    12. }if(args.length == 1 && args[0].equalsIgnoreCase("pl")){
    13. Sender.sendMessage(pm.getPlugins());
    14. }
    15. }else{
    16. Sender.sendMessage(getConfig().getString("Prefix").replace("&", "§") + getConfig().getString("noperm").replace("&", "§"));
    17. }
    18. }

    Eclipse says that the
    Code:java
    1. Sender.sendMessage(pm.getPlugins());

    Isn't right. It says:
    The method sendMessage(String) in the type CommandSender is not applicable for the
    arguments (Plugin[])
    Any idea on how to get my command to give me a list of the plugins I have? Thanks for the help :)
     
  2. Offline

    1Rogue

    Iterate over the plugin array it returns, and then for each Plugin instance get the description and add the name to a StringBuilder
     
  3. Offline

    random_username

    how would I do that? :)
     
  4. Offline

    1Rogue

    Code:java
    1. StringBuilder sb = new StringBuilder("Plugins: ");
    2. for (Plugin p : pm.getPlugins()) {
    3. sb.append(p.getName()).append(", ");
    4. }
    5. String list = sb.substring(0, sb.length() - 2);
     
  5. Offline

    random_username

    Thanks, this works. Btw, do you know how to make the number of plugins I have appear after the "Plugins" so It can be "Plugins (#): " in the string builder message? :)
     
  6. Offline

    sgavster

    random_username

    Code:java
    1. player.sendMessage("Plugins " + '(' + pm.getPlugins().length + ')');
    2.  

    or something :)
     
  7. Offline

    random_username

    Solved, thanks so much! :D
     
Thread Status:
Not open for further replies.

Share This Page