Solved Error occurred while enabling

Discussion in 'Plugin Development' started by Clybzotik, Feb 9, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    Clybzotik

    Hi, i get this problem. How i can fix it?

    Show Spoiler


    Error occurred while enabling KitPVP v0.1 (Is it up to date?)
    java.lang.IllegalArgumentException: Plugin already initialized!
    at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:183) ~[craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:60) ~[craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at kpvp.main.KitPVP.<init>(KitPVP.java:10) ~[?:?]
    at kpvp.main.Handler.<init>(Handler.java:15) ~[?:?]
    at kpvp.main.KitPVP.onEnable(KitPVP.java:44) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:403) [craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:381) [craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:330) [craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:422) [craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:383) [craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:338) [craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272) [craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:545) [craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_191]
    Caused by: java.lang.IllegalStateException: Initial initialization
    at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:186) ~[craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:60) ~[craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at kpvp.main.KitPVP.<init>(KitPVP.java:10) ~[?:?]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_191]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_191]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_191]
    at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_191]
    at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_191]
    at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:90) ~[craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:327) ~[craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:248) ~[craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.loadPlugins(CraftServer.java:305) ~[craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:205) ~[craftbukkit-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    ... 2 more
    [14:14:59] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [14:14:59] [Server thread/INFO]: Done (7,136s)! For help, type "help" or "?"
     
  2. Offline

    DerDonut

    Hey,
    could you please post your Main class?
     
  3. Offline

    Clybzotik

    Code:
    package kpvp.main;
    
    import java.io.File;
    import java.sql.*;
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class KitPVP extends JavaPlugin{
       
        public void onEnable() {
            Logger log = getLogger();
            log.info("/===================================/");
            log.info("/ Kit PVP v0.1 by Clybzotik enabled /");
            log.info("/===================================/");
            File config = new File(getDataFolder() + File.separator + "config.yml");
            if(!config.exists()) {
                getConfig().options().copyDefaults(true);
                saveDefaultConfig();
                getLogger().info("Create config...");
            }
            Connection c = null;
            Statement stmt = null;
            try {
                Class.forName("org.sqlite.JDBC");
                c = DriverManager.getConnection("jdbc:sqlite:" + getDataFolder() + File.separator + "Users.db");
                log.info("Get connection");
                stmt = c.createStatement();
                String sql = "CREATE TABLE IF NOT EXISTS USERS " +
                                "(ID INTEGER PRIMARY KEY AUTOINCREMENT , " +
                                " NICK           TEXT    NOT NULL UNIQUE, " + 
                                " KITS           TEXT    NOT NULL, " + 
                                " BALANCE        INT     NOT NULL, " + 
                                " KILLS          INT     NOT NULL, " + 
                                " DEATH          INT     NOT NULL) " ; 
                stmt.executeUpdate(sql);
                stmt.close();
                c.close();
            } catch ( Exception e ) {
                 System.err.println( e.getClass().getName() + ": " + e.getMessage() );
                 System.exit(0);
            } 
            Bukkit.getPluginManager().registerEvents(new Handler(), this);
            getCommand("stats").setExecutor(new CommandStats(this));
        }
    } [CODE]
     
  4. Offline

    timtower Ninja on the waves Moderator

    @Clybzotik Do you have multiple classes extending JavaPlugin?
     
  5. Offline

    DerDonut

    And what about the Handler class?
    Try to strt your plugin without registering the Handler as a listener. Its mentioned in the error so maybe you create a new instance of the Main?
     
  6. Offline

    Clybzotik

    No, I dont have.

    I tried, but the problem remained

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  7. Offline

    timtower Ninja on the waves Moderator

    @Clybzotik Do you have more plugins installed with the same main class?
     
  8. Offline

    Clybzotik

    UPD:
    The problem is to transfer the main class by this method:
    KitPVP plugin = new KitPVP();
     
  9. Offline

    DerDonut

    so you create a new instance of your main in anoher class do I understand that right?
     
  10. Offline

    Clybzotik

    Yes.
     
  11. Offline

    DerDonut

    Then I think we found the problem.
    To pass the instance create a constructor in each class which needs the main. Do not create a new plugin inside your plugin
     
  12. Offline

    Clybzotik

    Can you write an example?

    UPD:
    Something like that?
    Code:
        private KitPVP plugin;
        public Handler(KitPVP plugin) {
            this.plugin = plugin;
        }
    
    
     
    Last edited: Feb 9, 2019
  13. Offline

    DerDonut

    Of course.
    Lets say you need an instance of KitPvP in the class 'Handler':

    Create a constructor in the Handler class which takes a KitPvP instance as its parameter:
    Code:Java
    1. private KitPvP main;
    2.  
    3. public Handler(KitPvP main) {
    4. this.main = main;
    5. }


    And if you call this constructor in KitPvP you pass 'this':
    Code:Java
    1. Bukkit.getPluginManager().registerEvents(new Handler(this), this);
     
  14. Offline

    Clybzotik

    Thanks.
     
  15. Offline

    DerDonut

    you're welcome
     
Thread Status:
Not open for further replies.

Share This Page