Solved Getting plugin version returns me IllegalStateException

Discussion in 'Plugin Development' started by _TheTechGuy_, Sep 1, 2021.

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

    _TheTechGuy_

    So I was developing a plugin using SpigotAPI, and I wanted to include a command to view the version of the plugin. However, while doing so, the command is throwing a IllegalStateException: Initital initialization

    Code:java
    1.  
    2. public class GetVersion implements CommandExecutor {
    3. @Override
    4. public boolean onCommand(CommandSender player, Command command, String s, String[] args) {
    5. PluginDescriptionFile descriptionFile = new Main().getDescription();
    6. if (command.getName().equalsIgnoreCase("btversion")){
    7. player.sendMessage(ChatColor.YELLOW + "You are running [Plugin name here] " + ChatColor.GREEN + descriptionFile.getVersion());
    8. return true;
    9. }else{
    10. return false;
    11. }
    12. }
    13. }
    14.  

    What is wrong with the code?
     
    Last edited: Sep 1, 2021
  2. Online

    timtower Administrator Administrator Moderator

    @_TheTechGuy_ Can't do new Main()
    Need to get the original instance.
    Use a constructor to pass it along.
     
  3. Offline

    _TheTechGuy_

    Thanks a lot! It helped!
     
Thread Status:
Not open for further replies.

Share This Page