java.lang.IllegalArgumentException: Plugin already initialized. What's going on?

后端 未结 3 968
生来不讨喜
生来不讨喜 2021-01-29 08:50

When I\'m testing my new plugin an exception keeps getting thrown: java.lang.IllegalArgumentException: Plugin already initialized! Please help! Here\'s the code:



        
相关标签:
3条回答
  • 2021-01-29 09:26

    The stacktrace clearly tells where is the problem. What is a stack trace, and how can I use it to debug my application errors?
    The error:

    java.lang.IllegalArgumentException: Plugin already initialized!
    ...
    Caused by: java.lang.IllegalStateException: Initial initialization
    ...
    at me.plugin.example.Main.<init>(Main.java:19) ~[?:?]
    

    Your code:

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(new Main(), this);
    } //<-- 19th line
    

    And the problem is when you register your event you are creating a new instance of your Main class. So replace new Main()

    getServer().getPluginManager().registerEvents(new Main(), this);
    

    with this

    getServer().getPluginManager().registerEvents(this, this);
    
    0 讨论(0)
  • 2021-01-29 09:37

    I would really recommend you to put your event handler in a separate class.

    Try removing the below line

    getServer().getPluginManager().registerEvents(new Main(), this);
    

    and please don't ask your question several times.

    0 讨论(0)
  • 2021-01-29 09:41

    PluginAlreadyInitialized error occours when the .jar file contains more than one subclass of JavaPlugin class. Use the JavaPlugin class only once in all plugins from.

    0 讨论(0)
提交回复
热议问题