Solved Configuration File Help

Discussion in 'Plugin Development' started by GizmoRay, Sep 27, 2012.

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

    GizmoRay

    Hello Bukkiteers,
    I'm trying to set-up a config file for my plugin, however, when I load the sever I'm getting an error:
    Code:
    2012-09-27 19:39:12 [INFO] Starting minecraft server version 1.3.2
    2012-09-27 19:39:12 [INFO] Loading properties
    2012-09-27 19:39:12 [WARNING] server.properties does not exist
    2012-09-27 19:39:12 [INFO] Generating new properties file
    2012-09-27 19:39:12 [INFO] Default game type: SURVIVAL
    2012-09-27 19:39:12 [INFO] Generating keypair
    2012-09-27 19:39:12 [INFO] Starting Minecraft server on *:25565
    2012-09-27 19:39:12 [WARNING] **** FAILED TO BIND TO PORT!
    2012-09-27 19:39:12 [WARNING] The exception was: java.net.BindException: Address already in use: JVM_Bind
    2012-09-27 19:39:12 [WARNING] Perhaps a server is already running on that port?
    2012-09-27 19:40:56 [INFO] Starting minecraft server version 1.3.2
    2012-09-27 19:40:56 [INFO] Loading properties
    2012-09-27 19:40:56 [INFO] Default game type: SURVIVAL
    2012-09-27 19:40:56 [INFO] Generating keypair
    2012-09-27 19:40:56 [INFO] Starting Minecraft server on *:25565
    2012-09-27 19:40:56 [INFO] This server is running CraftBukkit version git-Bukkit-1.3.2-R0.2-b2371jnks (MC: 1.3.2) (Implementing API version 1.3.2-R0.2)
    2012-09-27 19:40:56 [WARNING] Failed to load operators list: java.io.FileNotFoundException: .\ops.txt (The system cannot find the file specified)
    2012-09-27 19:40:56 [WARNING] Failed to load white-list: java.io.FileNotFoundException: .\white-list.txt (The system cannot find the file specified)
    2012-09-27 19:40:56 [INFO] Preparing level "world"
    2012-09-27 19:40:56 [INFO] Preparing start region for level 0 (Seed: 6004475242151536623)
    2012-09-27 19:40:57 [INFO] ----- Bukkit Auto Updater -----
    2012-09-27 19:40:57 [INFO] It appears that you're running a Beta Build, when you've specified in bukkit.yml that you prefer to run Recommended Builds.
    2012-09-27 19:40:57 [INFO] If you would like to be kept informed about new Beta Build releases, it is recommended that you change 'preferred-channel' in your bukkit.yml to 'beta'.
    2012-09-27 19:40:57 [INFO] With that set, you will be told whenever a new version is available for download, so that you can always keep up to date and secure with the latest fixes.
    2012-09-27 19:40:57 [INFO] If you would like to disable this warning, simply set 'suggest-channels' to false in bukkit.yml.
    2012-09-27 19:40:57 [INFO] ----- ------------------- -----
    2012-09-27 19:40:57 [INFO] Preparing spawn area: 16%
    2012-09-27 19:40:58 [INFO] Preparing spawn area: 40%
    2012-09-27 19:40:59 [INFO] Preparing spawn area: 65%
    2012-09-27 19:41:00 [INFO] Preparing spawn area: 93%
    2012-09-27 19:41:01 [INFO] Preparing start region for level 1 (Seed: 6004475242151536623)
    2012-09-27 19:41:01 [INFO] Preparing spawn area: 20%
    2012-09-27 19:41:02 [INFO] Preparing spawn area: 56%
    2012-09-27 19:41:03 [INFO] Preparing spawn area: 97%
    2012-09-27 19:41:04 [INFO] Preparing start region for level 2 (Seed: 6004475242151536623)
    2012-09-27 19:41:04 [INFO] Preparing spawn area: 69%
    2012-09-27 19:41:05 [INFO] Done (8.611s)! For help, type "help" or "?"
    2012-09-27 19:45:07 [INFO] CONSOLE: Stopping the server..
    2012-09-27 19:45:07 [INFO] Stopping server
    2012-09-27 19:45:07 [WARNING] DSCT: socket closed
    2012-09-27 19:45:07 [INFO] Saving players
    2012-09-27 19:45:07 [INFO] Closing listening thread
    2012-09-27 19:45:07 [INFO] Saving worlds
    2012-09-27 19:45:07 [INFO] Saving chunks for level 'world'/Overworld
    2012-09-27 19:45:08 [INFO] Saving chunks for level 'world_nether'/Nether
    2012-09-27 19:45:09 [INFO] Saving chunks for level 'world_the_end'/The End
    2012-09-27 19:45:15 [INFO] Starting minecraft server version 1.3.2
    2012-09-27 19:45:15 [INFO] Loading properties
    2012-09-27 19:45:15 [INFO] Default game type: SURVIVAL
    2012-09-27 19:45:15 [INFO] Generating keypair
    2012-09-27 19:45:15 [INFO] Starting Minecraft server on *:25565
    2012-09-27 19:45:15 [INFO] This server is running CraftBukkit version git-Bukkit-1.3.2-R0.2-b2371jnks (MC: 1.3.2) (Implementing API version 1.3.2-R0.2)
    2012-09-27 19:45:15 [SEVERE] Could not load 'plugins\GoldPanningPlugin.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: File cannot be null
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:152)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:223)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:199)
        at net.minecraft.server.ServerConfigurationManagerAbstract.<init>(ServerConfigurationManagerAbstract.java:50)
        at net.minecraft.server.ServerConfigurationManager.<init>(SourceFile:11)
        at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:105)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:377)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.IllegalArgumentException: File cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:203)
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:170)
        at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:117)
        at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
        at com.gizmoray.goldpanning.GPpanning.<init>(GPpanning.java:17)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:148)
        ... 9 more
    2012-09-27 19:45:15 [INFO] Preparing level "world"
    2012-09-27 19:45:16 [INFO] Preparing start region for level 0 (Seed: 6004475242151536623)
    2012-09-27 19:45:16 [INFO] Preparing start region for level 1 (Seed: 6004475242151536623)
    2012-09-27 19:45:16 [INFO] ----- Bukkit Auto Updater -----
    2012-09-27 19:45:16 [INFO] It appears that you're running a Beta Build, when you've specified in bukkit.yml that you prefer to run Recommended Builds.
    2012-09-27 19:45:16 [INFO] If you would like to be kept informed about new Beta Build releases, it is recommended that you change 'preferred-channel' in your bukkit.yml to 'beta'.
    2012-09-27 19:45:16 [INFO] With that set, you will be told whenever a new version is available for download, so that you can always keep up to date and secure with the latest fixes.
    2012-09-27 19:45:16 [INFO] If you would like to disable this warning, simply set 'suggest-channels' to false in bukkit.yml.
    2012-09-27 19:45:16 [INFO] ----- ------------------- -----
    2012-09-27 19:45:16 [INFO] Preparing start region for level 2 (Seed: 6004475242151536623)
    2012-09-27 19:45:17 [INFO] Server permissions file permissions.yml is empty, ignoring it
    2012-09-27 19:45:17 [INFO] Done (1.103s)! For help, type "help" or "?"
    2012-09-27 19:46:46 [INFO] CONSOLE: Stopping the server..
    2012-09-27 19:46:46 [INFO] Stopping server
    2012-09-27 19:46:46 [INFO] Saving players
    2012-09-27 19:46:46 [WARNING] DSCT: socket closed
    2012-09-27 19:46:46 [INFO] Saving worlds
    2012-09-27 19:46:46 [INFO] Closing listening thread
    2012-09-27 19:46:46 [INFO] Saving chunks for level 'world'/Overworld
    2012-09-27 19:46:46 [INFO] Saving chunks for level 'world_nether'/Nether
    2012-09-27 19:46:46 [INFO] Saving chunks for level 'world_the_end'/The End
    2012-09-27 19:46:46 [INFO] Stopping server
    2012-09-27 19:47:16 [INFO] Starting minecraft server version 1.3.2
    2012-09-27 19:47:16 [INFO] Loading properties
    2012-09-27 19:47:16 [INFO] Default game type: SURVIVAL
    2012-09-27 19:47:16 [INFO] Generating keypair
    2012-09-27 19:47:16 [INFO] Starting Minecraft server on *:25565
    2012-09-27 19:47:16 [INFO] This server is running CraftBukkit version git-Bukkit-1.3.2-R0.2-b2371jnks (MC: 1.3.2) (Implementing API version 1.3.2-R0.2)
    2012-09-27 19:47:16 [SEVERE] Could not load 'plugins\GoldPanningPlugin.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: File cannot be null
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:152)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:223)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:199)
        at net.minecraft.server.ServerConfigurationManagerAbstract.<init>(ServerConfigurationManagerAbstract.java:50)
        at net.minecraft.server.ServerConfigurationManager.<init>(SourceFile:11)
        at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:105)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:377)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.IllegalArgumentException: File cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:203)
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:170)
        at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:117)
        at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
        at com.gizmoray.goldpanning.GPpanning.<init>(GPpanning.java:17)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:148)
        ... 9 more
    2012-09-27 19:47:16 [INFO] Preparing level "world"
    2012-09-27 19:47:16 [INFO] Preparing start region for level 0 (Seed: 6004475242151536623)
    2012-09-27 19:47:16 [INFO] Preparing start region for level 1 (Seed: 6004475242151536623)
    2012-09-27 19:47:17 [INFO] ----- Bukkit Auto Updater -----
    2012-09-27 19:47:17 [INFO] It appears that you're running a Beta Build, when you've specified in bukkit.yml that you prefer to run Recommended Builds.
    2012-09-27 19:47:17 [INFO] If you would like to be kept informed about new Beta Build releases, it is recommended that you change 'preferred-channel' in your bukkit.yml to 'beta'.
    2012-09-27 19:47:17 [INFO] With that set, you will be told whenever a new version is available for download, so that you can always keep up to date and secure with the latest fixes.
    2012-09-27 19:47:17 [INFO] If you would like to disable this warning, simply set 'suggest-channels' to false in bukkit.yml.
    2012-09-27 19:47:17 [INFO] ----- ------------------- -----
    2012-09-27 19:47:17 [INFO] Preparing start region for level 2 (Seed: 6004475242151536623)
    2012-09-27 19:47:17 [INFO] Server permissions file permissions.yml is empty, ignoring it
    2012-09-27 19:47:17 [INFO] Done (1.057s)! For help, type "help" or "?"
    
    Any help would be greatly appreciated. Let me know if you need any of the code I've written to load the config file.

    Thanks in advance for any help!
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    GizmoRay
    It would appear you have a logic error in your code.
     
  3. Offline

    GizmoRay

    I'm not getting any warnings, though. It was working perfectly before this.
     
  4. Offline

    Sagacious_Zed Bukkit Docs

    Logic errors do not set off the syntax error checker.
     
  5. Offline

    GizmoRay

    Sagacious_Zed
    Alright, figured out what it was. It was the way that I was calling an Integer from the config file. How would you recommend you call an int from the config file? I'm having difficulty with the config, don't know what's going wrong.

    Thank you again!
     
  6. Offline

    Sagacious_Zed Bukkit Docs

    i would invoke the getInt method on the FileConfiguration you are trying to to retrieve values from. probably the instance returned by getConfig() method of JavaPlugin
     
  7. Offline

    GizmoRay

    Sagacious_Zed
    That's precisely what was giving me the errors.

    Code:
    public int bgsrs = getConfig().getInt("goldspawnratesand");
        public int bgsrc = getConfig().getInt("goldspawnrateclay");
        public int bgsrg = getConfig().getInt("goldspawnrategravel");
        public int bgsrd = getConfig().getInt("goldspawnratedirt");
        public int cgsrs = getConfig().getInt("cauldrongoldspawnratesand");
        public int cgsrc = getConfig().getInt("cauldrongoldspawnrateclay");
        public int cgsrg = getConfig().getInt("cauldrongoldspawnrategravel");
        public int cgsrd = getConfig().getInt("cauldrongoldspawnratedirt");
    and

    Code:
        private int bgsrc = new GPpanning().bgsrc;
        private int bgsrd = new GPpanning().bgsrd;
        private int bgsrg = new GPpanning().bgsrg;
        private int bgsrs = new GPpanning().bgsrs;
        private int cgsrs = new GPpanning().cgsrs;
        private int cgsrc = new GPpanning().cgsrc;
        private int cgsrd = new GPpanning().cgsrd;
        private int cgsrg = new GPpanning().cgsrg;
     
  8. Offline

    Sagacious_Zed Bukkit Docs

    GizmoRay
    Well the solution would depend on the error.
     
  9. Offline

    GizmoRay

    Sagacious_Zed
    Code:
    [SEVERE] Could not load 'plugins\GoldPanningPlugin.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: File cannot be null
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:152)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:223)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:199)
        at net.minecraft.server.ServerConfigurationManagerAbstract.<init>(ServerConfigurationManagerAbstract.java:50)
        at net.minecraft.server.ServerConfigurationManager.<init>(SourceFile:11)
        at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:105)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:377)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.IllegalArgumentException: File cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:203)
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:170)
        at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:117)
        at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
        at com.gizmoray.goldpanning.GPpanning.<init>(GPpanning.java:18)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:148)
        ... 9 more
    That's what was creating the logic error, you mentioned earlier. If I remove the code completely, it goes away, until then my plugin won't load.

    Thank you again, I really appreciate the help!
     
  10. Offline

    Sagacious_Zed Bukkit Docs

    GizmoRay
    I still don't see the code that set your plugin up to fail. specifically it looks like something happened
    at com.gizmoray.goldpanning.GPpanning.<init>(GPpanning.java:18)
     
  11. Offline

    GizmoRay

    Code:
    public int bgsrs = getConfig().getInt("goldspawnratesand");
    This is line 18, not entirely sure what's happening.
     
  12. Offline

    Sagacious_Zed Bukkit Docs

    Well im still missing context from the rest of the class, and possibly the rest of the plugin.
     
  13. Offline

    GizmoRay

    Code:
    package com.gizmoray.goldpanning;
     
    import java.io.File;
    import java.util.logging.Logger;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.*;
    import org.bukkit.*;
    import org.bukkit.configuration.file.FileConfiguration;
     
    public class GPpanning extends JavaPlugin { 
        public final Logger log = Logger.getLogger("Minecraft");
        public static GPpanning plugin;
        public File configFile;
        private FileManager fm;
        public int bgsrs = getConfig().getInt("goldspawnratesand");
        public int bgsrc = getConfig().getInt("goldspawnrateclay");
        public int bgsrg = getConfig().getInt("goldspawnrategravel");
        public int bgsrd = getConfig().getInt("goldspawnratedirt");
        public int cgsrs = getConfig().getInt("cauldrongoldspawnratesand");
        public int cgsrc = getConfig().getInt("cauldrongoldspawnrateclay");
        public int cgsrg = getConfig().getInt("cauldrongoldspawnrategravel");
        public int cgsrd = getConfig().getInt("cauldrongoldspawnratedirt");
        @Override
        public void onEnable(){
            this.fm = new FileManager(this); this.fm.load();
            getServer().getPluginManager().registerEvents(new PluginListener(), this);
         
            PluginDescriptionFile pdfFile = this.getDescription();
            this.log.info(pdfFile.getName() + " " + " v" + pdfFile.getVersion() + " : Has been enabled");
         
            loadConfiguration();
        }
     
          private void loadConfiguration()
          {
            getConfig().options().copyDefaults(true);
     
            saveConfig();
          }
    }
    Hopefully this helps...
     
  14. Offline

    Sagacious_Zed Bukkit Docs

    Its obvious. You cannot call getConfig until your plugin is initialized. Calling the getConfig method during object construction means certain values are still not set. You will need to move the assignments into onEnable.
     
  15. Offline

    GizmoRay

    Awesome! That worked, thank you very much! Stupid mistake on my part.

    Thank you again!

    Sagacious_Zed
    It's loading a zero for the value though... Is there any reason?

    Code:
    package com.gizmoray.goldpanning;
     
    import java.io.File;
    import java.util.logging.Logger;
     
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.*;
     
    public class GPpanning extends JavaPlugin {
        public final Logger log = Logger.getLogger("Minecraft");
        public static GPpanning plugin;
        public File configFile;
        private FileManager fm;
        public int bgsrs;
        public int bgsrc;
        public int bgsrg;
        public int bgsrd;
        public int cgsrs;
        public int cgsrc;
        public int cgsrg;
        public int cgsrd;
        public boolean cmdStart = true;
     
     
        @Override
        public void onEnable(){
            loadConfiguration();
            this.fm = new FileManager(this); this.fm.load();
            setValues();
            getServer().getPluginManager().registerEvents(new PluginListener(), this);
       
            PluginDescriptionFile pdfFile = this.getDescription();
            this.log.info(pdfFile.getName() + " " + " v" + pdfFile.getVersion() + " : Has been enabled");
       
        }
     
        @EventHandler(priority = EventPriority.HIGHEST)
        private void setValues(){
            bgsrs = getConfig().getInt("goldspawnratesand");
            bgsrc = getConfig().getInt("goldspawnrateclay");
            bgsrg = getConfig().getInt("goldspawnrategravel");
            bgsrd = getConfig().getInt("goldspawnratedirt");
            cgsrs = getConfig().getInt("cauldrongoldspawnratesand");
            cgsrc = getConfig().getInt("cauldrongoldspawnrateclay");
            cgsrg = getConfig().getInt("cauldrongoldspawnrategravel");
            cgsrd = getConfig().getInt("cauldrongoldspawnratedirt");
          return;
        }
        @EventHandler(priority = EventPriority.HIGHEST)
        private void loadConfiguration(){
            //CAULDRON
            getConfig().addDefault("cauldrongoldspawnratesand", Integer.valueOf(19));
            getConfig().addDefault("cauldrongoldspawnrateclay", Integer.valueOf(38));
            getConfig().addDefault("cauldrongoldspawnratedirt", Integer.valueOf(22));
            getConfig().addDefault("cauldrongoldspawnrategravel", Integer.valueOf(28));
       
            //Bowl
            getConfig().addDefault("goldspawnratesand", Integer.valueOf(9));
            getConfig().addDefault("goldspawnrateclay", Integer.valueOf(19));
            getConfig().addDefault("goldspawnrategravel", Integer.valueOf(10));
            getConfig().addDefault("goldspawnratedirt", Integer.valueOf(11));
     
            getConfig().options().copyDefaults(true);
     
            saveConfig();
          }
    }
    I'm sorry that I have so many questions.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  16. Offline

    Sagacious_Zed Bukkit Docs

    GizmoRay
    getInt will return 0 if the underlying value is 0 or it cannot read the value.
     
  17. Offline

    GizmoRay

    Sagacious_Zed
    I'm sure it can read the value, I tested it with the logger, and it outputted just fine. As far as I can tell, the underlying value is being set to what's in the config.

    Thanks!
     
Thread Status:
Not open for further replies.

Share This Page