Problem with Bukkit's Configuration

Discussion in 'Plugin Development' started by Acrobot, May 14, 2011.

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

    Acrobot

    When coding 3.0 of iConomyChestShop's, I have tried to make better configuration reader, so I tried:

    Code:
     private static File configFile = new File("plugins/iConomyChestShop/config.yml");
        private static Configuration config = new Configuration(configFile);
      
        public static void setUp(){
            if(!configFile.exists()){
                try {
                    configFile.createNewFile();
                    Logging.log("Successfully created blank configuration file");
                } catch (Exception e) {
                    Logging.log("Couldn't create configuration file!");
                }
            }
            load();
        }
    
        public static void load(){
            config.load();
        }
    
        public static boolean getBoolean(String node){
            return config.getBoolean(node, asd(node));
        }
    
        public static int getInteger(String node){
            return config.getInt(node, 0);
        }
    
        public static double getDouble(String node){
            return config.getDouble(node, -1);
        }
    
        public static boolean asd(String property){
            System.out.println("PROPERTY DOES NOT EXIST: " + property);
            return false;
        }
    
    It seems like "asd" gets called every time I do getBoolean(node) , even when I have my config file.

    setUp() gets called in onEnable()

    Once again, I can read the value in getBoolean if I remove the "asd", but if not, asd(node) gets called every time.

    Am I doing something wrong, or is it some kind of Bukkit's bug?
     
  2. Offline

    DreadKyller

    what is the asd there for? I checked it out and it's not a normal method, could you paste that code too?
     
  3. Offline

    Acrobot

    ?
    Asd is a method that returns boolean, so it would fit into "default" of getBoolean(String node, Boolean default)

    Asd should get called every time boolean configuration doesn't exist, however, it is called every time, even if I have configuration in file. If I just go getBoolean(node, false); it runs fine, it shows me value that I have in file, however getBoolean(node, asd(node)); shows me that I haven't got my property (which worked without asd) every time.

    asd gets declared in code I posted.
     
  4. Offline

    halvors

    Configuration class already have functions for "get".
     
  5. Offline

    Acrobot

    @halvors
    This is not the point.
    If you look, I am able to getBoolean, but I want to set default value if it's not present.

    For example, if I have boolean value in config "useDB", I do:

    Code:
    ConfigClass.getBoolean("useDB");
    
    (Not actually named ConfigClass, just for easier understanding)

    If it's not found, I want to set it to default, so I do

    Code:
    config.getBoolean(node, setDefaultValueFor(node));
    
    So, it should get "useDB" from config file, and if it's not present, it should execute "setDefaultValueFor(node)".

    However, when I use it, setDefaultValueFor(node) gets called EVERY TIME I read the value, and I have the propery in config file :/

    Also, when I just do

    Code:
    config.getBoolean(node, false);
    
    It works fine, returns sometimes true, and sometimes false (depends on the config file)

    To sum it:

    Code:
    config.getBoolean(node, false);
    
    works fine, however in
    Code:
    config.getBoolean(node, setDefaultValue(node));
    
    setDefaultValue(node) gets called EVERY time I try to get the boolean from config file, and not only if the value isn't present.
     
  6. Offline

    DreadKyller

    strange. I don't see why it would, because all the asd does is returns false, maybe try just public boolean instead of static.
     
  7. Offline

    Acrobot

    @DreadKyller
    I can't do public boolean, because I would reference it from static context then - It won't work, unless I make everything non-static. I'll test it later today.
     
  8. Offline

    DreadKyller

    Oo, that could be a lot of work, I doubt that's it anyways.
     
Thread Status:
Not open for further replies.

Share This Page