GAH, making a reload command

Discussion in 'Spigot Plugin Development' started by TheMcBaws, Jul 22, 2018.

  1. So, I am making a plugin rn. I have the command set up and it calls a reload method. The command is in a separate class than the main class.
    Code (Java):
    public static void reload() {
            log.info("Reloading Config");
            Bukkit.getPluginManager().getPlugin("AJoin").reloadConfig();
        }
    Code (Text):
    [15:07:07 INFO]: [AJoin] Reloading Config
    [15:07:07 WARN]: Unexpected exception while parsing console command "ajoin reload"
    org.bukkit.command.CommandException: Unhandled exception executing 'ajoin reload' in net.atlanthea.themcbaws.ajoin.commands.AJoin(ajoin)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:144) ~[server.jar:git-Bukkit-809c399]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:629) ~[server.jar:git-Bukkit-809c399]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchServerCommand(CraftServer.java:615) [server.jar:git-Bukkit-809c399]
            at net.minecraft.server.v1_12_R1.DedicatedServer.aP(DedicatedServer.java:408) [server.jar:git-Bukkit-809c399]
            at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:372) [server.jar:git-Bukkit-809c399]
            at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:651) [server.jar:git-Bukkit-809c399]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:555) [server.jar:git-Bukkit-809c399]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_181]
    Caused by: java.lang.IllegalArgumentException: Plugin already initialized!
            at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:98) ~[server.jar:git-Bukkit-809c399]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:60) ~[server.jar:git-Bukkit-809c399]
            at net.atlanthea.themcbaws.ajoin.main.Main.<init>(Main.java:15) ~[?:?]
            at net.atlanthea.themcbaws.ajoin.main.Main.reload(Main.java:63) ~[?:?]
            at net.atlanthea.themcbaws.ajoin.commands.AJoin.execute(AJoin.java:26) ~[?:?]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[server.jar:git-Bukkit-809c399]
            ... 7 more
    Caused by: java.lang.IllegalStateException: Initial initialization
            at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:101) ~[server.jar:git-Bukkit-809c399]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:60) ~[server.jar:git-Bukkit-809c399]
            at net.atlanthea.themcbaws.ajoin.main.Main.<init>(Main.java:15) ~[?:?]
            at net.atlanthea.themcbaws.ajoin.main.Main.reload(Main.java:63) ~[?:?]
            at net.atlanthea.themcbaws.ajoin.commands.AJoin.execute(AJoin.java:26) ~[?:?]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[server.jar:git-Bukkit-809c399]
            ... 7 more
    >
    Does anyone have any advice?
     
  2. The plugin is already initialised, check:
    1. You don’t have more than one plugin with the same package name
    2. You don’t call new Main() anywhere, as @NetherGoblin said
    3. For reload config, just do this.reloadConfig(); if it’s the main class, or call the instance.reloadConfig(); don’t get the plugin instance from Bukkit.