When I\'m testing my new plugin an exception keeps getting thrown: java.lang.IllegalArgumentException: Plugin already initialized! Please help! Here\'s the code:
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);
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.