1.15.2 Plugin Already Initialized error

Discussion in 'Spigot Plugin Development' started by Majesity, May 30, 2020.

  1. Hi all!
    I need to access instances of my Main class in other classes, so here's an example of one of the constructors and instance variable (plugin is a reference to the Main class):
    Code (Java):
    private Plugin plugin;
       
        public ListenerThrowableItems(Plugin plugin) {
            this.plugin=plugin;
        }
    But for some reason the server doesn't like it. My plugin has been working for nearly 2 months and it just started doing this today and I don't understand why. Here's the error:
    Code (Text):
    Error occurred while enabling SCBPlugin v1.0 (Is it up to date?)
    29.05 22:59:30 [Server] INFO java.lang.IllegalArgumentException: Plugin already initialized!
    29.05 22:59:30 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:199) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:52) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.zapto.majesity.scb.Main.<init>(Main.java:22) ~[?:?]
    29.05 22:59:30 [Server] INFO at org.zapto.majesity.scb.KitDirectory.<init>(KitDirectory.java:56) ~[?:?]
    29.05 22:59:30 [Server] INFO at org.zapto.majesity.scb.ListenerThrowableItems.<init>(ListenerThrowableItems.java:65) ~[?:?]
    29.05 22:59:30 [Server] INFO at org.zapto.majesity.scb.Main.onEnable(Main.java:91) ~[?:?]
    29.05 22:59:30 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:351) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugin(CraftServer.java:464) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugins(CraftServer.java:378) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.bukkit.craftbukkit.v1_15_R1.CraftServer.reload(CraftServer.java:835) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.bukkit.Bukkit.reload(Bukkit.java:620) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:27) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.bukkit.craftbukkit.v1_15_R1.CraftServer.dispatchCommand(CraftServer.java:723) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at net.minecraft.server.v1_15_R1.PlayerConnection.handleCommand(PlayerConnection.java:1658) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at net.minecraft.server.v1_15_R1.PlayerConnection.a(PlayerConnection.java:1498) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at net.minecraft.server.v1_15_R1.PacketPlayInChat.a(PacketPlayInChat.java:47) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at net.minecraft.server.v1_15_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at net.minecraft.server.v1_15_R1.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at net.minecraft.server.v1_15_R1.TickTask.run(SourceFile:18) [Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeTask(SourceFile:144) [Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at net.minecraft.server.v1_15_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) [Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeNext(SourceFile:118) [Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at net.minecraft.server.v1_15_R1.MinecraftServer.ba(MinecraftServer.java:918) [Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at net.minecraft.server.v1_15_R1.MinecraftServer.executeNext(MinecraftServer.java:911) [Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.awaitTasks(SourceFile:127) [Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at net.minecraft.server.v1_15_R1.MinecraftServer.sleepForTick(MinecraftServer.java:895) [Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:828) [Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at java.lang.Thread.run(Thread.java:748) [?:1.8.0_211]
    29.05 22:59:30 [Server] INFO Caused by: java.lang.IllegalStateException: Initial initialization
    29.05 22:59:30 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:202) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:52) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.zapto.majesity.scb.Main.<init>(Main.java:22) ~[?:?]
    29.05 22:59:30 [Server] INFO at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_211]
    29.05 22:59:30 [Server] INFO at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_211]
    29.05 22:59:30 [Server] INFO at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_211]
    29.05 22:59:30 [Server] INFO at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_211]
    29.05 22:59:30 [Server] INFO at java.lang.Class.newInstance(Class.java:442) ~[?:1.8.0_211]
    29.05 22:59:30 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:394) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:301) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.bukkit.craftbukkit.v1_15_R1.CraftServer.loadPlugins(CraftServer.java:353) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO at org.bukkit.craftbukkit.v1_15_R1.CraftServer.reload(CraftServer.java:833) ~[Spigot_Latest_1.15.2.jar:git-Spigot-2f5d615-aae46f8]
    29.05 22:59:30 [Server] INFO ... 19 more
    The thing I changed today was the constructor for the KitDirectory class, which is here:
    Code (Java):
    protected static ArrayList<Arena> activeArenas;
        protected ArrayList<Arena> idleArenas;
        private HashMap<String,String> metaToConfigBrawler = new HashMap<String,String>();
        private HashMap<String,String> playerDamageCause;
        private HashMap<String,Long> playerDamageTime;
       
        public KitDirectory() {
            idleArenas = new ArrayList<Arena>();
            activeArenas = new ArrayList<Arena>();
            metaToConfigBrawler.put("§6Blaze","blaze");
            // ^^ there are more of these but I got rid of them so it's not as long for this post
            playerDamageCause = new HashMap<String,String>();
            playerDamageTime = new HashMap<String,Long>();
        }
    I don't see why this is a problem?? Please help. Thank you very much for your time.
     
  2. Your main class is the ONLY class that should extend JavaPlugin. If this is not the case, are you creating a new instance of Main by any chance?
     
  3. My main class is the only one that extends JavaPlugin. Otherwise, no I am not creating a new instance of Main... idk why this error is happening
     
  4. Code (Java):
    29.05 22:59:30 [Server] INFO at org.zapto.majesity.scb.Main.<init>(Main.java:22) ~[?:?]
    What's at this line?
     
  5. Why are you using 'Plugin' instead of 'Main'?
    Try with "private Main plugin", instead of "private Plugin plugin"

    I'm not pretty sure, but try.
     
  6. I didn't even notice, haha.
    That definitely will do the trick.
     
    • Friendly Friendly x 1
  7. That would not fix the issue.
    Are you sure you're not doing 'new Main()' somewhere?

    If this is not the case, check that your plugin is not double in the plugins folder under a different name.
     
  8. Hm, you're right. In my head I was assuming he created a new instance of Plugin right there for some reason, I guess I shouldn't be up all night. In the end we're back to what I first answered here, that he's creating a new instance somewhere.

    Either way, @Majesity has to show the code from his main class, and other classes if necessary.
     
    #8 yPedx, May 30, 2020
    Last edited: May 30, 2020