Saving/Loading Objects

Discussion in 'Plugin Development' started by flash1110, Apr 10, 2015.

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

    flash1110

    Basically, I'm trying to, as the title says, save and load objects that are oriented.

    I'm saving them like this:
    Code:
    for (Koth koth : getKoths()) {
                settings.getRegion().set("koth." + koth.getName(), koth.getName());
               
                settings.getRegion().set("koth." + koth.getName() + ".world1", koth.getCuboid().getWorld().getName());
                settings.getRegion().set("koth." + koth.getName() + ".x1", koth.getCuboid().getLowerX());
                settings.getRegion().set("koth." + koth.getName() + ".y1", koth.getCuboid().getLowerY());
                settings.getRegion().set("koth." + koth.getName() + ".z1", koth.getCuboid().getLowerZ());
               
                settings.getRegion().set("koth." + koth.getName() + ".world2", koth.getCuboid().getWorld().getName());
                settings.getRegion().set("koth." + koth.getName() + ".x2", koth.getCuboid().getUpperX());
                settings.getRegion().set("koth." + koth.getName() + ".y2", koth.getCuboid().getUpperY());
                settings.getRegion().set("koth." + koth.getName() + ".z2", koth.getCuboid().getUpperZ());
               
                settings.getRegion().set("koth." + koth.getName() + ".captime", koth.getCaptureTime());
               
                settings.saveRegion();
            }
    I'm loading them like this:
    Code:
    for (String str : settings.getRegion().getConfigurationSection("koth").getKeys(false)) {
               
                String name = settings.getRegion().getString("koth." + str);
                World loc1W = Bukkit.getServer().getWorld(settings.getRegion().getString("koth." + str + ".world1"));
                int loc1X = settings.getRegion().getInt("koth." + str + ".x1");
                int loc1Y = settings.getRegion().getInt("koth." + str + ".y1");
                int loc1Z = settings.getRegion().getInt("koth." + str + ".z1");
               
                World loc2W = Bukkit.getServer().getWorld(settings.getRegion().getString("koth." + str + ".world2"));
                int loc2X = settings.getRegion().getInt("koth." + str + ".x2");
                int loc2Y = settings.getRegion().getInt("koth." + str + ".y2");
                int loc2Z = settings.getRegion().getInt("koth." + str + ".z2");
               
                int captureTime = settings.getRegion().getInt("koth." + str + ".captime");
               
                Location loc1 = new Location(loc1W, loc1X, loc1Y, loc1Z);
                Location loc2 = new Location(loc2W, loc2X, loc2Y, loc2Z);
           
                Koth toSave = new Koth(name, new Cuboid(loc1, loc2), captureTime);
               
                addKoth(name, toSave);
                System.out.println(Main.getKoth(name));
                loc1 = null;
                loc2 = null;
            }
    However, on reload the koths aren't loaded up, however they are saved. There are no stacktraces in console.
     
  2. Offline

    nverdier

    @flash1110 What does
    print out?
     
  3. Offline

    flash1110

  4. Offline

    caderape

    @flash1110 the method looks good. It's may be the way you load the file
     
  5. Offline

    flash1110

    @caderape I don't see any errors in the way I load the file.
     
  6. Offline

    Zombie_Striker

    @flash1110 Did you debug? Are you sure that 'str' is equal to 'koth.getName();'? Are you sure that 'name' and 'toSave' are not null?
     
  7. Offline

    flash1110

    @Zombie_Striker Yes, I did. That's why I had the test line, which worked.
     
  8. Offline

    Tecno_Wizard

Thread Status:
Not open for further replies.

Share This Page