[Help] Saveing/Loading

Discussion in 'Plugin Development' started by DreadKyller, May 17, 2011.

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

    DreadKyller

    I have tried many tutorials that show how to save and load info with java, and have tried in many different ways to use the Configuration, saving seems to work good, actually writing to a file. But when I try to load and of the information, no matter what I do, it always returns null, I have the load() before trying to load it and save() after and my .yml file is setup like so:
    PHP:
    Rewards:
        
    Stone:10
        Wood_Pickaxe
    :1
        Wood_Spade
    :1
        Wood_Axe
    :1
    the property is a material type and then the number is the amount of that to put in the stack, yet I get an error while trying to get it.
    PHP:
    File pfile = new File("plugins//LoginRewards");
                if(!(
    pfile.exists())){
                    
    pfile.mkdirs();
                }
                
    File file = new File("plugins//LoginRewards//Rewards.yml");
                if(!(
    file.exists())){
                    try{
                        
    file.createNewFile();
                    }catch(
    Exception e){
                    }
                }
                
    Object[] props = {};
                
    Configuration rs = new Configuration(file);
                
    rs.load();
                
    props rs.getKeys("Rewards").toArray();
                for(
    int i=0;i<props.length;i++){
                    
    Material mat Material.getMaterial((String)props[i]);
                    
    int amount=1;
                    
    amount Integer.valueOf((String) rs.getProperty((String)props[i]));
                    
    Player player event.getPlayer();
                    
    ItemStack gift= new ItemStack(mat);
                    
    gift.setAmount(amount);
                    
    player.getInventory().addItem(gift);
                    
    rs.save();
                }
            }
    the problem is that the getKeys() is always returning null, so the Object[] never contains anything and it can't convert null into an integer or a material. I do not get why it's not working.

    Is there something wrong with my script?
     
  2. Offline

    desmin88

    @DreadKyller
    Try removing the double slashes in your declaration to file.

    File file = new File("plugins/LoginRewards/Rewards.yml
     
  3. Offline

    DreadKyller

    it's getting the file, i know that for sure, cause before I fixed a different error saying "result found on config load, found character "/t which can not start any token" I fixed that and now I get this, I completely forgot about tabs, but if I remove the "//" and replace with "/" is give this error:
    PHP:
    "/" is an invalid syntax exchange proper ones include(//  ///  /-/)
    but I'll try it.

    @desmin88 : nope, does not make any difference at all

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

    desmin88

    @DreadKyller
    Do a System.out.println(rs)
    To check if its null after loading.
     
  5. Offline

    DreadKyller

    @desmin88 :all I get is
    Code:
    org.bukkit.util.config.Configuration@78aa80
    yeah, I tried to println many things, rs.toString(), rs.byteData(), etc... but everything ends up as @781180
    I just want to know if someone sees in my script why it's failing.

    I'm now trying to use Property instead on config, but it still not working, at least it's not giving errors, but it's not even writing...

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

    nisovin

    Well, for one, your yml file is invalid. You must have a space after the colons, I believe.
     
  7. Offline

    DreadKyller

    @nisovin, nope, because when useing the setProperty("Matname", "number") it does it just like I have it.
     
Thread Status:
Not open for further replies.

Share This Page