Guest User

save/load

a guest
Aug 20th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. //List<Arena> arenas;
  2.  
  3.  
  4. private static File mainDir = Main.getDataFolder();
  5. private static File arenas = new File(mainDir, "arenas");
  6.  
  7. public static void save(){
  8.     for(Arena a:arenas){
  9.         File f = new File(arenas, a.getId + ".yml");
  10.         if(!f.exists()){
  11.                 try {
  12.                     f.createNewFile();
  13.                 } catch (IOException e) {
  14.                     e.printStackTrace();
  15.                 }
  16.         }
  17.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  18.         yml.set("id", a.getId());
  19.         yml.set("firstx", a.locPlayer1().getX());
  20.         yml.set("firsty", a.locPlayer1().getY());
  21.         yml.set("firstz", a.locPlayer1().getZ());
  22.         yml.set("scndx", a.locPlayer2().getX());
  23.         yml.set("scndy", a.locPlayer2().getY());
  24.         yml.set("scndz", a.locPlayer2().getZ());
  25.         yml.set("name", a.getName()); //you should add this getter cause i cannot create an arena without that, and this string is set to private
  26.         //it should NOT happen, but nobody knows...
  27.         if(a.locPlayer1().getWorld().getName() == a.locPlayer2().getWorld().getName()){
  28.             yml.set("world", a.locPlayer1().getWorld().getName());
  29.         }      
  30.     }
  31. }
  32. public static void load(){
  33.     for(File f:arenas.listFiles()){
  34.         YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
  35.         Arena a = new Arena(yml.getInt("id"), yml.getString("name"));
  36.         for(World w: Bukkit.getWorlds()){
  37.             if(w.getName() = yml.getString("world")){
  38.                 Location loc1 = new Location(w, yml.getDouble("firstx"), yml.getDouble("firsty"), yml.getDouble("firstz"));
  39.                 Location loc2 = new Location(w, yml.getDouble("scndx"), yml.getDouble("scndy"), yml.getDouble("scndz"));
  40.                 a.setPlayer1(loc1);
  41.                 a.setPlayer2(loc2);
  42.             }
  43.         }
  44.         //again, it SHOULD be set, but it's just in case it would throw null;
  45.         //make setter for name and ID
  46.         a.setID(yml.getInt("id"));
  47.         a.setName(yml.getString("name"));
  48.     }
  49. }
Add Comment
Please, Sign In to add comment