How can i get my plugins version from the plugin.yml

Discussion in 'Plugin Development' started by SoThatsIt, Jun 26, 2012.

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

    SoThatsIt

    hi im wondering if theres a command to get the plugin version i have put in the plugin.yml?

    this is probably a noob question but i haven't been working on bukkit plugins for a while and just recently started getting back into it.
     
  2. Offline

    one4me

    getDescription().getVersion()
     
  3. Offline

    CRAZYxMUNK3Y

    Code:java
    1.  
    2. PluginDescriptionFile pdf = this.getDescription(); //Gets plugin.yml
    3. pdf.getVersion(); //Gets the version
    4.  
     
    GalaxyPrisonMc likes this.
  4. Offline

    Gravity

    pdf.getVersion(), not Servsion
     
    chasechocolate likes this.
  5. Offline

    SoThatsIt

    thanks for the help guys and the quick response! :D
     
  6. Offline

    CRAZYxMUNK3Y

    Derp, don't know how i managed that...
     
  7. Offline

    MrDent009

    Code:
        PluginDescriptionFile pdfFile = this.getDescription();
        this.log.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " [enable/disable]");
    BOOM!

    JUST BLEW YOUR MIND!
     
    chasechocolate likes this.
  8. Offline

    Gravity

    Except for the fact that you don't need to do that; Bukkit automatically logs enabling and disabling :)
     
    Zidkon likes this.
  9. Offline

    MrDent009

    Nice to know. Thank you :)
     
  10. Offline

    asb1230

    Could anyone tell me why this is giving me an unexpected error?
    Code:
    public class HelpExecutor extends JavaPlugin implements CommandExecutor {
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] agrs){
            PluginDescriptionFile pdf = this.getDescription();
           
            sender.sendMessage(ChatColor.GREEN + "[EI] Version:" + pdf.getVersion());
     
  11. Offline

    zack6849

    You arent checking the commands name.

    Code:
    if(cmd.getName().equalsIgnoreCase("yourcommand"){
        sender.sendMessage(ChatColor.GREEN + "[EI] Version: " + pdf.getVersion());
        return true;
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  12. Offline

    chasechocolate

    public class HelpExecutor extends JavaPlugin implements CommandExecutor {

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    if(cmd.getName().equalsIgnoreCase("whateveryourcommandis"){
    PluginDescriptionFile pdf = this.getDescription();
    sender.sendMessage(ChatColor.GREEN + "[EI] Version: " + pdf.getVersion());
    return true;
    }
    return false;
     
  13. Offline

    asb1230

    Ohhh. I had it set up so that in the main class it said getCommand(blah) and instantiated this class. So when I am getting the description it means of the command, and it has to know the command first. I think?

    This is still giving me a nullPointerException at the sender.sendMessage line.
    Code:
    public class HelpExecutor extends JavaPlugin implements CommandExecutor {
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] agrs){
            if(cmd.getName().equalsIgnoreCase("emptyinventory")){
                PluginDescriptionFile pdf = this.getDescription();
                sender.sendMessage(ChatColor.GREEN + "[EI] Version: " + ChatColor.DARK_GREEN + pdf.getVersion());
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  14. zack6849 If this is the only command in the plugin.yml there's really no need to check its name.
    chasechocolate He can name his variables like he wants, that isn't the error, too.
    asb1230 "I had it set up so that in the main class it said getCommand(blah) and instantiated this class." <- so this isn't your main class but it extends JavaPlugin? Problem found!
     
  15. Offline

    chasechocolate

    Inside the curly brackets of your if statement at the bottom, you need to put "return true" and just outside of the if statement, you need to put "return false"
     
  16. chasechocolate Also wrong. I bet this will work like a charm if it's the only class file in the jar:
    Code:java
    1. public class MainPluginClass extends JavaPlugin {
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] agrs){
    3. PluginDescriptionFile pdf = this.getDescription();
    4. sender.sendMessage(ChatColor.GREEN + "[EI] Version: " + ChatColor.DARK_GREEN + pdf.getVersion());
    5. return true;
    6. }
    7. }

    The problem is that he's doing something like this:
    Code:java
    1. public class MainPluginClass extends JavaPlugin {
    2. public void onEnable() {
    3. getCommand("dacmd").setExecutor(new HelpExecutor());
    4. }

    and breaks an important rule with it: Never ever make another class than the main class extending JavaPlugin. Of course getDescription() will return null if not called from the main classes main instance.
    How to fix? Either join the two classes into one or write a constructor for the HelpExecutor class and handle over the reference to the plugins main instance there.
     
    asb1230 likes this.
  17. Offline

    asb1230

    Oh I see. So in the main class if I "extend JavaPlugin implement Listener implement CommandExecutor" (I have an event in the main class so I need Listener) and move this code there, it will work?
     
  18. asb1230 Yes, but you don't need to implement CommandExecutor as JavaPlugin still implements this (over a few edges) and also you don't need something like getCommand("foo").setExecutor(this); as the main class is the default executor anyway. ;)
     
  19. Lol what they said :D
     
Thread Status:
Not open for further replies.

Share This Page