Plugin Help Plugin not creating files

Discussion in 'Plugin Help/Development/Requests' started by BestMcPlayers, Apr 5, 2015.

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

    BestMcPlayers

    I've used a differnt method for YMAL configuration, but I'm going back to classic Bukkit FileConfiguration.

    I get this error:
    Error (open)

    [01:31:09] [Server thread/INFO]: [Bullet-Proof] Enabling Bullet-Proof v1.0
    [01:31:09] [Server thread/WARN]: null
    java.io.FileNotFoundException: plugins\Bullet-Proof\config.yml (The system cannot find the path specified)
    at java.io.FileInputStream.open(Native Method) ~[?:1.8.0_25]
    at java.io.FileInputStream.<init>(FileInputStream.java:138) ~[?:1.8.0_25]
    at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:167) ~[spigot-1.8.jar:git-Spigot-fa7cbf9-42ebec1]
    at com.BigDaddyK.BulletProof.BulletProof.onEnable(BulletProof.java:50) [Bullet-Proof-1.0.jar:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) [spigot-1.8.jar:git-Spigot-fa7cbf9-42ebec1]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:335) [spigot-1.8.jar:git-Spigot-fa7cbf9-42ebec1]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot-1.8.jar:git-Spigot-fa7cbf9-42ebec1]
    at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:355) [spigot-1.8.jar:git-Spigot-fa7cbf9-42ebec1]
    at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:315) [spigot-1.8.jar:git-Spigot-fa7cbf9-42ebec1]
    at net.minecraft.server.v1_8_R1.MinecraftServer.q(MinecraftServer.java:402) [spigot-1.8.jar:git-Spigot-fa7cbf9-42ebec1]
    at net.minecraft.server.v1_8_R1.MinecraftServer.k(MinecraftServer.java:370) [spigot-1.8.jar:git-Spigot-fa7cbf9-42ebec1]
    at net.minecraft.server.v1_8_R1.MinecraftServer.a(MinecraftServer.java:325) [spigot-1.8.jar:git-Spigot-fa7cbf9-42ebec1]
    at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:211) [spigot-1.8.jar:git-Spigot-fa7cbf9-42ebec1]
    at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:494) [spigot-1.8.jar:git-Spigot-fa7cbf9-42ebec1]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_25]
    [01:31:09] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [01:31:09] [Server thread/INFO]: Done (10.523s)! For help, type "help" or "?"



    My main file.java:
    Plugin.java (open)

    Code:
        public BulletProof plugin;
        public BulletProofUtils util;
        FileConfiguration mainConfig;
        FileConfiguration adminConfig;
        FileConfiguration banConfig;
        File mainConfigFile;
        File adminConfigFile;
        File banConfigFile;
       
        @Override
        public void onLoad()
        {
            mainConfigFile = new File(getDataFolder(), "config.yml");
            adminConfigFile = new File(getDataFolder(), "admins.yml");
            banConfigFile = new File(getDataFolder(), "bans.yml");
           
            mainConfig = new YamlConfiguration();
            adminConfig = new YamlConfiguration();
            banConfig = new YamlConfiguration();
           
           
            PluginDescriptionFile pdf = plugin.getDescription();
            Log.LOG("Enabled, running version " + pdf.getVersion() + "!");
            Log.LOG("Made by Kell Shep(BigDaddyK)");
        }
       
        @Override
        public void onEnable()
        {
    
            try
            {
                //Loads YMAL files.
                mainConfig.load(mainConfigFile);
                adminConfig.load(adminConfigFile);
                banConfig.load(banConfigFile);
            }
            catch (IOException ex)
            {
                Log.LOG(ex);
            }
            catch (InvalidConfigurationException ex2)
            {
                Log.LOG("Couldn't load configuration files!");
                Log.LOG(ex2);
            }
        }
     
  2. Offline

    nverdier

    @BestMcPlayers The problem is that the files don't exist, when you try to load them. If you want an easy way to create a bunch of configs, you could use the Config class of EnviousAPI, link in signature.
     
    BestMcPlayers likes this.
  3. Offline

    BestMcPlayers

    I'll check it out, thanks. Do you have an example I can use?
     
  4. Offline

    nverdier

    BestMcPlayers likes this.
  5. Offline

    BestMcPlayers

    Thanks, but can anyone tell we what I was doing wrong? Fix up my code?
     
  6. Offline

    nverdier

    @BestMcPlayers
     
  7. Offline

    BestMcPlayers

    I like you're config class thing, but can you fix the code for me. I want to learn it using classic bukkit. Remember, I could just go back to my old method of configuration, but I want to use classic Bukkit.

    How would I fix my code?
     
  8. Offline

    nverdier

    @BestMcPlayers I won't spoonfeed, but I will tell you this: Create the files before loading them.
     
  9. Offline

    BestMcPlayers

    I hate to bother you so much, but this is what I tried.

    New Code (open)

    Code:
        public BulletProof plugin;
        public BulletProofUtils util;
        //
        public FileConfiguration mainConfig;
        public FileConfiguration adminConfig;
        public FileConfiguration banConfig;
        //
        public File mainConfigFile;
        public File adminConfigFile;
        public File banConfigFile;
        //
    
    
        @Override
        public void onLoad()
        {
           
            PluginDescriptionFile pdf = plugin.getDescription();
            Log.LOG("Enabled, running version " + pdf.getVersion() + "!");
            Log.LOG("Made by Kell Shep(BigDaddyK)");
        }
       
        @Override
        public void onEnable()
        {
            mainConfigFile = new File(getDataFolder(), "config.yml");
            adminConfigFile = new File(getDataFolder(), "admins.yml");
            banConfigFile = new File(getDataFolder(), "bans.yml");
       
            try
            {
                firstrun();
            }
            catch (Exception ex)
            {
                Log.LOG(ex);
            }
           
            try
            {
                mainConfig.load(mainConfigFile);
                adminConfig.load(adminConfigFile);
                banConfig.load(banConfigFile);
            }
            catch (IOException  | InvalidConfigurationException ex)
            {
                Log.LOG(ex);
            }
           
            mainConfig = new YamlConfiguration();
            adminConfig = new YamlConfiguration();
            banConfig = new YamlConfiguration();
           
      }
    
       
        @Override
        public void onDisable()
        {
            Log.LOG("Disabled!");
            Log.LOG("Made by Kell Shep(BigDaddyK)");
        }
       
        public void copy(InputStream in, File file)
        {
            try
            {
                OutputStream out = new FileOutputStream(file);
                byte[] buf = new byte[1024];
                int len;
               
                while((len = in.read(buf)) > 0)
                {
                    out.write(buf, 0 ,len);
                }
               
                out.close();
                in.close();
            }
            catch (Exception e)
            {
            }
        }
        private void firstrun() throws Exception
        {
            if(!mainConfigFile.exists())
            {
                mainConfigFile.getParentFile().mkdirs();
                copy(getResource("config.yml"), mainConfigFile);
            }
                if(!banConfigFile.exists())
                {
                    banConfigFile.getParentFile().mkdirs();
                    copy(getResource("bans.yml"), banConfigFile);
                }
                    if(!adminConfigFile.exists())
                    {
                        adminConfigFile.getParentFile().mkdirs();
                        copy(getResource("config.yml"), adminConfigFile);
                    }
        }


    I get what you're saying in the post above, but now I'm getting different errors. Damnnit, I hate Bukkit.
     
  10. Offline

    nverdier

  11. Offline

    BestMcPlayers

    It's just a Java logger I made for my plugin. I tried removing it, and it still didn't work, so I don't think that's the issue.

    Edit: It's creating the files now, but I'm still getting an error.

    New Error (open)

    Code:
    [08:00:21] [Server thread/INFO]: Starting minecraft server version 1.8
    [08:00:22] [Server thread/INFO]: Loading properties
    [08:00:22] [Server thread/INFO]: Default game type: SURVIVAL
    [08:00:22] [Server thread/INFO]: Generating keypair
    [08:00:22] [Server thread/INFO]: Starting Minecraft server on 192.168.1.34:25565
    [08:00:26] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-42ebec1 (MC: 1.8) (Implementing API version 1.8-R0.1-SNAPSHOT)
    [08:00:27] [Server thread/INFO]: [Bullet-Proof] Loading Bullet-Proof v1.0
    [08:00:27] [Server thread/ERROR]: null initializing Bullet-Proof v1.0 (Is it up to date?)
    java.lang.NullPointerException
        at com.BigDaddyK.BulletProof.BulletProof.onLoad(BulletProof.java:38) ~[?:?]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugins(CraftServer.java:292) [craftbukkit.jar:git-Bukkit-42ebec1]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.<init>(CraftServer.java:249) [craftbukkit.jar:git-Bukkit-42ebec1]
        at net.minecraft.server.v1_8_R1.PlayerList.<init>(PlayerList.java:69) [craftbukkit.jar:git-Bukkit-42ebec1]
        at net.minecraft.server.v1_8_R1.DedicatedPlayerList.<init>(SourceFile:14) [craftbukkit.jar:git-Bukkit-42ebec1]
        at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:133) [craftbukkit.jar:git-Bukkit-42ebec1]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:473) [craftbukkit.jar:git-Bukkit-42ebec1]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_25]
    [08:00:27] [Server thread/INFO]: Preparing level "world"
    [08:00:28] [Server thread/INFO]: Preparing start region for level 0 (Seed: 2368943288190414149)
    [08:00:29] [Server thread/INFO]: Preparing spawn area: 1%
    [08:00:30] [Server thread/INFO]: Preparing spawn area: 13%
    [08:00:31] [Server thread/INFO]: Preparing spawn area: 33%
    [08:00:32] [Server thread/INFO]: Preparing spawn area: 75%
    [08:00:33] [Server thread/INFO]: Preparing spawn area: 94%
    [08:00:33] [Server thread/INFO]: Preparing start region for level 1 (Seed: 2368943288190414149)
    [08:00:34] [Server thread/INFO]: Preparing spawn area: 48%
    [08:00:35] [Server thread/INFO]: Preparing spawn area: 87%
    [08:00:35] [Server thread/INFO]: Preparing start region for level 2 (Seed: 2368943288190414149)
    [08:00:36] [Server thread/INFO]: [Bullet-Proof] Enabling Bullet-Proof v1.0
    [08:00:36] [Server thread/ERROR]: Error occurred while enabling Bullet-Proof v1.0 (Is it up to date?)
    java.lang.NullPointerException
        at com.BigDaddyK.BulletProof.BulletProof.onEnable(BulletProof.java:63) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[craftbukkit.jar:git-Bukkit-42ebec1]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:327) [craftbukkit.jar:git-Bukkit-42ebec1]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-42ebec1]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:340) [craftbukkit.jar:git-Bukkit-42ebec1]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:312) [craftbukkit.jar:git-Bukkit-42ebec1]
        at net.minecraft.server.v1_8_R1.MinecraftServer.q(MinecraftServer.java:394) [craftbukkit.jar:git-Bukkit-42ebec1]
        at net.minecraft.server.v1_8_R1.MinecraftServer.k(MinecraftServer.java:362) [craftbukkit.jar:git-Bukkit-42ebec1]
        at net.minecraft.server.v1_8_R1.MinecraftServer.a(MinecraftServer.java:317) [craftbukkit.jar:git-Bukkit-42ebec1]
        at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:190) [craftbukkit.jar:git-Bukkit-42ebec1]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:473) [craftbukkit.jar:git-Bukkit-42ebec1]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_25]
    [08:00:36] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [08:00:36] [Server thread/INFO]: Done (9.148s)! For help, type "help" or "?"
    [08:00:43] [Server thread/WARN]: Can't keep up! Did the system time change, or is the server overloaded? Running 2517ms behind, skipping 50 tick(s)
    
     
  12. Offline

    nverdier

  13. Offline

    BestMcPlayers

    Nothing, I don't think so. Just skipped a line.
     
  14. Offline

    nverdier

    @BestMcPlayers Try re-exporting, restarting your server, and posting the new log.
     
  15. Offline

    BestMcPlayers

    Ok, I'll post my code on more time:
    Code (open)

    Code:
    public class BulletProof extends JavaPlugin
    {
        public BulletProof plugin;
        public BulletProofUtils util;
        //
        public FileConfiguration mainConfig;
        public FileConfiguration adminConfig;
        public FileConfiguration banConfig;
        //
        public File mainConfigFile;
        public File adminConfigFile;
        public File banConfigFile;
        //
        private Logger log;
    
        @Override
        public void onLoad()
        {
         
            PluginDescriptionFile pdf = plugin.getDescription();
            log.log(Level.INFO, "Enabled, running version {0}!", pdf.getVersion());
            log.log(Level.INFO, "Made by Kell Shep(BigDaddyK)");
        }
     
        @Override
        public void onEnable()
        {
            log = getLogger();
             
            mainConfigFile = new File(getDataFolder(), "config.yml");
            adminConfigFile = new File(getDataFolder(), "admins.yml");
            banConfigFile = new File(getDataFolder(), "bans.yml");
            try
            {
                firstrun();
            }
            catch (Exception ex)
            {
    
            }
            mainConfig = new YamlConfiguration();
            adminConfig = new YamlConfiguration();
            banConfig = new YamlConfiguration();
            try
            {
                mainConfig.load(mainConfigFile);
                adminConfig.load(adminConfigFile);
                banConfig.load(banConfigFile);
            }
            catch (IOException  | InvalidConfigurationException ex)
            {
    
            }
      }
    
        @Override
        public void onDisable()
        {
            log.log(Level.INFO, "Disabled!");
            log.log(Level.INFO, "Made by Kell Shep(BigDaddyK)");
        }
        public void copy(InputStream in, File file)
        {
            try
            {
                OutputStream out = new FileOutputStream(file);
                byte[] buf = new byte[1024];
                int len;
             
                while((len = in.read(buf)) > 0)
                {
                    out.write(buf, 0 ,len);
                }
             
                out.close();
                in.close();
            }
            catch (Exception e)
            {
            }
        }
     
        private void firstrun() throws Exception
        {
            if(!mainConfigFile.exists())
            {
                mainConfigFile.getParentFile().mkdirs();
                copy(getResource("config.yml"), mainConfigFile);
            }
                if(!banConfigFile.exists())
                {
                    banConfigFile.getParentFile().mkdirs();
                    copy(getResource("bans.yml"), banConfigFile);
                }
                    if(!adminConfigFile.exists())
                    {
                        adminConfigFile.getParentFile().mkdirs();
                        copy(getResource("config.yml"), adminConfigFile);
                    }
        }
    }


    Error (open)

    Code:
    [09:03:28] [Server thread/INFO]: Starting minecraft server version 1.8
    [09:03:28] [Server thread/INFO]: Loading properties
    [09:03:28] [Server thread/INFO]: Default game type: SURVIVAL
    [09:03:28] [Server thread/INFO]: Generating keypair
    [09:03:29] [Server thread/INFO]: Starting Minecraft server on 192.168.1.34:25565
    [09:03:31] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-42ebec1 (MC: 1.8) (Implementing API version 1.8-R0.1-SNAPSHOT)
    [09:03:31] [Server thread/INFO]: [BulletProof] Loading BulletProof v1.0
    [09:03:31] [Server thread/ERROR]: null initializing BulletProof v1.0 (Is it up to date?)
    java.lang.NullPointerException
        at com.BigDaddyK.BulletProof.BulletProof.onLoad(BulletProof.java:35) ~[?:?]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugins(CraftServer.java:292) [craftbukkit.jar:git-Bukkit-42ebec1]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.<init>(CraftServer.java:249) [craftbukkit.jar:git-Bukkit-42ebec1]
        at net.minecraft.server.v1_8_R1.PlayerList.<init>(PlayerList.java:69) [craftbukkit.jar:git-Bukkit-42ebec1]
        at net.minecraft.server.v1_8_R1.DedicatedPlayerList.<init>(SourceFile:14) [craftbukkit.jar:git-Bukkit-42ebec1]
        at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:133) [craftbukkit.jar:git-Bukkit-42ebec1]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:473) [craftbukkit.jar:git-Bukkit-42ebec1]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_25]
    [09:03:32] [Server thread/INFO]: Preparing level "world"
    [09:03:32] [Server thread/INFO]: Preparing start region for level 0 (Seed: 2368943288190414149)
    [09:03:33] [Server thread/INFO]: Preparing spawn area: 7%
    [09:03:34] [Server thread/INFO]: Preparing spawn area: 34%
    [09:03:35] [Server thread/INFO]: Preparing spawn area: 73%
    [09:03:36] [Server thread/INFO]: Preparing start region for level 1 (Seed: 2368943288190414149)
    [09:03:37] [Server thread/INFO]: Preparing spawn area: 52%
    [09:03:37] [Server thread/INFO]: Preparing start region for level 2 (Seed: 2368943288190414149)
    [09:03:38] [Server thread/INFO]: [BulletProof] Enabling BulletProof v1.0
    [09:03:38] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [09:03:38] [Server thread/INFO]: Done (6.825s)! For help, type "help" or "?"
    [09:03:45] [Server thread/WARN]: Can't keep up! Did the system time change, or is the server overloaded? Running 2887ms behind, skipping 57 tick(s)
    [09:04:06] [Server thread/WARN]: Can't keep up! Did the system time change, or is the server overloaded? Running 7113ms behind, skipping 142 tick(s)
    
     
  16. Offline

    nverdier

  17. Offline

    BestMcPlayers

    Fixed it. I don't know why but this was causing my issue. Removed it and it worked. I can't tell you why.
    @nverdier Thank you for being the only one who helped.

    What caused the error (open)

    Code:
            PluginDescriptionFile pdf = plugin.getDescription();
            log.log(Level.INFO, "Enabled, running version {0}!", pdf.getVersion());
            log.log(Level.INFO, "Made by Kell Shep(BigDaddyK)");
     
  18. Offline

    nverdier

    @BestMcPlayers Probably 'plugin' or 'log' was null. But you don't need to log enable/disable messages! Bukkit already does this for you :D

    But no problem :p Always happy to help.
     
Thread Status:
Not open for further replies.

Share This Page