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

て烟熏妆下的殇ゞ 提交于 2019-12-02 13:58:48

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);
Creepsy

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!