Solved List plugins using command

Discussion in 'Plugin Development' started by plisov, Jan 28, 2016.

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

    plisov

    Hello,
    I am currently trying to create a plugin where when you type /auth it will display a list of plugins that are currently being used by the server. But the plugins should only show if the plugin was coded by me and if they are being used currently on the server. I've got the auth command setup but I can't figure out how to list the plugins that were coded by me and if they are active on the server.
    Any help is much appreciated,
    plisov
     
  2. Offline

    Zombie_Striker

    @plisov
    1. Use PluginManager.getPlugin("NAME-OF-PLUGIN")
    2. If that object is null, the plugin is not on the server
    3. Else, the plugin is enabled.
     
  3. Offline

    plisov

    PluginManager.getPlugin("Exo");
    is turning up red. When I type just PluginManager. , it doesn't show getPlugin
     
  4. Offline

    Zombie_Striker

    @plisov
    That is because PluginManager is not a object you can reference. You would need to get the PluginManager instance instead by getting the Server instance using getServer, and using .getPluginManager() (The same way you get the plugin manager for registering events.)
     
  5. Offline

    teej107

    Zombie_Striker likes this.
  6. Offline

    plisov

    Would I need to put Bukkit.getServer().getPluginManager().getPlugins() into the auth command?
    Also, where would I put
    public final class PluginDescriptionFile extends Object {
    }

    Finally, I don't understand how to get the author's name from the yml
     
  7. Offline

    Xerox262

    @plisov An enchanced for loop for the plugins
    Code:
    for (JavaPlugin plugin : Bukkit.getPluginManager().getPlugins()) {
       // Get plugin description file then check authors
    }
    JavaPlugin#getDescription(); to get the plugin description file
    PluginDescriptionFile#getAuthors(); to get the authors, null check that before checking if it contains your name.
     
  8. Offline

    plisov

    Are you sure it's not supposed to be
    Code:
    for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
                       // Get plugin description file then check authors
                    }
    because otherwise Bukkit.getPluginManager().getPlugins() turns red
     
  9. Offline

    Xerox262

    @plisov Yes, use Plugin instead of JavaPlugin, JavaPlugin is the only class that implements Plugin so it doesn't really make a difference.
     
  10. Offline

    plisov

    Alright, when I type Plugin.getDescription() getDescription turns red. When I just type Plugin. all I see is .class and this
     
  11. Offline

    teej107

    @plisov You need to get an instance of the Plugin object. When they say ClassName#methodName(), they mean instanceOfObject#methodName()
     
  12. Offline

    plisov

    Okay, so I've managed to get everything not 'red', now I need to figure out how to display the plugins.
    Code:
    if (cmd.getName().equalsIgnoreCase("auth")) {
                player.sendMessage(ChatColor.RED + "-----------------------------------------------------");
                player.sendMessage(ChatColor.BLUE + "This server uses the following plugins");
              
               for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
                    plugin.getDescription().getAuthors();
                }
              
                player.sendMessage(ChatColor.RED + "-----------------------------------------------------");
            }
     
  13. Offline

    Xerox262

    Inside your for loop, check that authors is not null, then check if it contains your name, if it does then show it with plugin.getDescription().getName();
     
  14. Offline

    plisov

    Okay, thanks for that. Now I've done
    Code:
            if (cmd.getName().equalsIgnoreCase("auth")) {
                player.sendMessage(ChatColor.RED + "-----------------------------------------------------");
                player.sendMessage(ChatColor.BLUE + "This server uses the following plugins ");
               
                for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
                    if(plugin.getDescription().getAuthors() == null) {
                        return false;
                    } else if(plugin.getDescription().getAuthors().equals("plisov")){
                        plugin.getDescription().getName();
                    }
                }
               
                player.sendMessage(ChatColor.RED + "-----------------------------------------------------");
            }
    But it doesn't show the plugins in game and I can't figure out what I'm doing wrong.
     
  15. Offline

    Xerox262

    getAuthors() returns a string list, this means it cannot equal a string, It can however contain it, use plugin.getDescription().getAuthors().contains("plisov")
     
  16. Offline

    plisov

    Code:
    if (cmd.getName().equalsIgnoreCase("auth")) {
                player.sendMessage(ChatColor.RED + "-----------------------------------------------------");
                player.sendMessage(ChatColor.BLUE + "This server uses the following plugins ");
              
                for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
                    if(plugin.getDescription().getAuthors() == null) {
                        return false;
                    } else if(plugin.getDescription().getAuthors().contians("plisov")){
                        plugin.getDescription().getName();
                    }
                }
              
                player.sendMessage(ChatColor.RED + "-----------------------------------------------------");
            }
    I've tried what you suggested but still it's not showing up.
     
  17. Offline

    Xerox262

    You need to actually show it, using Player#sendMessage(String); or Bukkit.broadcastMessage(String); right now all you're doing is getting it.
     
  18. Offline

    plisov

    Well that was a stupid mistake. :p Wasn't thinking.
     
  19. Offline

    Xerox262

    Don't forget to set the thread to solved if it worked :)
     
  20. Offline

    plisov

    Yep it worked! Thanks!
     
Thread Status:
Not open for further replies.

Share This Page