Listing Commands from plugin's plugin.yml

Discussion in 'Plugin Development' started by The Gaming Grunts, Feb 12, 2014.

Thread Status:
Not open for further replies.
  1. Hey everyone! So, I'm trying to list all the commands from my plugin's plugin.yml in order to make a help menu of sorts. This is what I have so far, but it doesn't work at all:

    Code:java
    1. for(Plugin plugin : Bukkit.getPluginManager().getPlugins()){
    2. if (plugin.getName() == "RankPoints"){
    3. List<Command> cmdList = PluginCommandYamlParser.parse(plugin);
    4. for(int i=0; i < cmdList.size(); i++){
    5. sender.sendMessage(cmdList.get(i).getAliases().toString());
    6. }
    7. }
    8. }


    I'd be grateful if someone can help me fix this or at least point me in the right direction. Thanks :)
     
  2. Offline

    97WaterPolo

    The Gaming Grunts
    Usually I would just redo it all, but this will return the commands.

    Code:java
    1. getDescription().getCommands();


    I don't use this one, but I use
    Code:java
    1. getServer().getLogger().info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    2. getServer().getLogger().info(getDescription().getName() + " Version: " + getDescription().getVersion() + "By: "getDescription().getAuthors() + " has been enabled!");
    3. getServer().getLogger().info("Please suggest ideas by sending a PM at: " + getDescription().getWebsite());
     
  3. Offline

    xTrollxDudex

    The Gaming Grunts
    By the way, you could just simplify the code a bit by using getPlugin(String).getDescription() and loop through all the commands...
     
  4. xTrollxDudex 97waterpolo
    1 problem solved. I had to change == to .equals(). Here's the new code:

    Code:java
    1. for(Plugin plugin : Bukkit.getPluginManager().getPlugins()){
    2. if (plugin.getName().equals("RankPoints")){
    3. List<Command> cmdList = PluginCommandYamlParser.parse(plugin);
    4. for(int i=0; i < cmdList.size(); i++){
    5. sender.sendMessage(cmdList.get(i).toString());
    6. }
    7. }
    8. }


    Now it displays messages like "org.bukkit.command.PluginCommand(command, pluginName)". How can I get only the command name? I could use something like substring(), but that wouldn't narrow it down enough
     
  5. Offline

    97WaterPolo

    The Gaming Grunts
    I never tried using the getDescription method for commands, so I can't help any more! :p Good luck!
     
  6. Offline

    xTrollxDudex

    The Gaming Grunts
    Also, your for loop can be simplified to a for-each loop :p
    Remember that it is a list of COMMANDS. Remember making commands? You can get the command name using getName().
     
Thread Status:
Not open for further replies.

Share This Page