Getting Commands From a Plugin

Discussion in 'Plugin Development' started by DeanDip, Sep 19, 2011.

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

    DeanDip

    The PluginDescrptionFile class has methods to return various info about a plugin, one of which is getCommands(), but the problem is that it returns the data as an Object data type instead of a certain data type like PluginCommand[] or List<PluginCommand>.

    I don't know what to do to get the commands data from that object. I've tried casting it into PluginCommand[], List<PluginCommand>, and LinkedHashMap (Because the runtime error said something about not being able to cast LinkedHashMap into whatever I casted it into, but when I used LinkedHashMap it said that it couldn't cast the values from it into PluginCommand or something like that.)

    If someone knows how to translate that object into something that can be used in the PluginCommand data type or even any other way to get data of all commands from a plugin, I would appreciate the help.

    edit: Solution Found! Solution is in my post below.
     
  2. Offline

    geekygenius

    Why would you need a command list? If you are doing something where you want commands to map to a class or a method (please use a class), then you can make an array of Command Objects, and use the getLabel() function to search for the right one.
     
  3. Offline

    DeanDip

    Basically, I'm creating a gui help plugin for Spout that will automatically create command listings with descriptions and usage (when available) for plugins enabled on the server. I want it to work without any given information from server owners if they don't provide any, so getLabel() won't work for me.

    I'm going to have a look at Essential's source code, if it's available, to see what they did for their help command because somehow they were able to get all command info.

    edit: I found out an easy solution while looking through the bukkit source code! It's also far easier than what Essentials did!

    All you have to do is import org.bukkit.command.PluginCommandYamlParser;
    and then do
    Code:
    List<Command> commands = PluginCommandYamlParser.parse(plugin);
    plugin would be of the data type Plugin

    What Essentials did is kinda like what's in PluginCommandYamlParser.
     
Thread Status:
Not open for further replies.

Share This Page