Get the version or another field from another plugin

Discussion in 'Resources' started by Jaker232, Dec 26, 2011.

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

    Jaker232

    I have rarely seen people asking how to catch versions or other plugin YAML fields from your plugin. It's just really that simple. I'll teach you how to get the plugin with AN API.

    Step 1 - Download the plugin you want to view
    This is essential.

    Step 2 - Put the .jar in your Build Path
    This will allow your plugin to read from another plugin.

    Step 3 - Make the line to whatever you need
    If you want to catch the other plugin's version, you'll need something to print to. I suggest 'log.info("");' or 'player.sendMessage("");'

    Step 4 - The Rest
    Now that we have done basic essential stuff, now we need to type in our plugin's name. For this example, I'll catch the version from PermissionsEx.

    Code:java
    1.  
    2. PermissionsEx.getPlugin();
    3.  

    This catches the plugin. Remove the ';' for each code update you do for this step.

    Code:java
    1.  
    2. PermissionsEx.getPlugin().getDescription();
    3.  

    Almost done.. Remove the ';' again and type in the next code. DO NOT MAKE NEW LINES.

    Code:java
    1.  
    2. PermissionsEx.getPlugin().getDescription().getVersion();
    3.  

    Congrats, you have found your version from a plugin.

    If the plugin DOES NOT HAVE AN API, I advise you to look at @r3Fuze 's post under this post.
     
    RROD likes this.
  2. The .getPlugin() part will only work for plugins where the developer added that method. Another way of doing it is
    Code:java
    1. Bukkit.getServer().getPluginManager().getPlugin("PluginName").getDescription()...
     
    DrAgonmoray and NuclearW like this.
  3. Offline

    Jaker232

    Good idea. I will add that as method 2.
     
    r3Fuze likes this.
  4. Offline

    Sleaker

    @Jaker232 - again another critical issue with your 'tutorial'. You can't do this with the majority of plugins. In fact PEX is the only plugin I know of that has a getPlugin method.
     
    ZNickq likes this.
  5. Offline

    NuclearW

    I highly suggest @r3Fuze 's method being the preferred method.

    Although even then you should be doing some null checking.
     
  6. Offline

    user_43347

    No, that should not be method two, it should be the only method.
    Code:
    PluginManager pm = getServer().getPluginManager();
    Plugin p = pm.getPlugin("MyPlugin");
    if (p != null) {
        PluginDescriptionFile pdf = p.getDescription();
        String version = pdf.getVersion();
    }
     
Thread Status:
Not open for further replies.

Share This Page