Getting IllegalArgumentException: Plugin already initialized

Discussion in 'Spigot Plugin Development' started by ZanderMan9, May 11, 2015.

  1. This is a very strange situation. Whenever I load up my latest plugin (a gambling plugin) it gives me this exception: http://pastebin.com/5AY5tk4J

    I am very familiar with this exception, as I had a battle with it a while back. I eventually fixed it by updating to the latest version of CraftBukkit. I tried updating to the latest version this time (I am using spigot 1.8.3 now) and it's still giving me the same error.

    I know there are several causes for this, but I'm sure none of these are my problem.
    1. Multiple classes extending JavaPlugin - I only have ONE class (my main class) extending JavaPlugin.
    2. Creating multiple instances of said class - I have thoroughly searched my code and I know for a fact I'm never creating any new instances of it.
    I'm referencing the same .jar in my project that I'm using to run my plugin.

    Are there any other causes? Is this a known problem with the latest build?
     
  2. Having the plugin twice in your plugins folder is also an issue. Post your code.
     
  3. I have made sure it isn't in the plugins folder twice.
    This is the code: http://pastebin.com/GPSe6fhx (some has been redacted so it can't just be copy/pasted and work)
     
  4. What is exactly on
    Code (Text):
    Main.java:7
    ?

    Also, is vault in your depend in your plugin.yml?
    Your plugin could be loading before vault and then trying to disable itself.
     
  5. Aha, that might be the case. I had forgotten to add the dependency. I'll check now.

    EDIT: I added the dependency, and that's all working, but I'm still getting the same error. It would appear
    Code (Text):

    private RegisteredServiceProvider<Economy> economyProvider;
     
    is on line 7 of Main.java (Unless that includes import statements, in which case it's import org.bukkit.command.CommandSender; )
     
    #5 ZanderMan9, May 11, 2015
    Last edited: May 11, 2015
  6. Yeah you cant cut out lines when we are trying to follow a stacktrace that says the line that is a problem.

    Also the BulkitScheduler was created to prevent this
    Code (Text):
    @Override
            public void run()
            {
                try
                {
                    Thread.sleep(300000);
                }
                catch (InterruptedException e)
                {
                    return;
                }
                closeBetting();
                endBetting();
    You cant access bukkit methods async the broadcast is fine as chat is async but you are pushing it :p
     
  7. Why is
    Code (Text):
        private RegisteredServiceProvider<Economy> economyProvider;
    outside the onEnable?
    The vault api looks like this:
    Code (Text):
        private boolean setupEconomy()
        {
            RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
            if (economyProvider != null) {
                economy = economyProvider.getProvider();
            }

            return (economy != null);
        }
     
  8. Ok then what is going on is you have two programs running with the same full class name. This is actually really likely with a the naming you are using. The classes full name is core.Main. You should be using a package like this "me. <yourName>.<pluginName>" unless you have a github in which you may want to go with "io.github. <githubUsernam>. <projectName>".