Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //List<Arena> arenas;
- private static File mainDir = Main.getDataFolder();
- private static File arenas = new File(mainDir, "arenas");
- public static void save(){
- for(Arena a:arenas){
- File f = new File(arenas, a.getId + ".yml");
- if(!f.exists()){
- try {
- f.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
- yml.set("id", a.getId());
- yml.set("firstx", a.locPlayer1().getX());
- yml.set("firsty", a.locPlayer1().getY());
- yml.set("firstz", a.locPlayer1().getZ());
- yml.set("scndx", a.locPlayer2().getX());
- yml.set("scndy", a.locPlayer2().getY());
- yml.set("scndz", a.locPlayer2().getZ());
- 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
- //it should NOT happen, but nobody knows...
- if(a.locPlayer1().getWorld().getName() == a.locPlayer2().getWorld().getName()){
- yml.set("world", a.locPlayer1().getWorld().getName());
- }
- }
- }
- public static void load(){
- for(File f:arenas.listFiles()){
- YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
- Arena a = new Arena(yml.getInt("id"), yml.getString("name"));
- for(World w: Bukkit.getWorlds()){
- if(w.getName() = yml.getString("world")){
- Location loc1 = new Location(w, yml.getDouble("firstx"), yml.getDouble("firsty"), yml.getDouble("firstz"));
- Location loc2 = new Location(w, yml.getDouble("scndx"), yml.getDouble("scndy"), yml.getDouble("scndz"));
- a.setPlayer1(loc1);
- a.setPlayer2(loc2);
- }
- }
- //again, it SHOULD be set, but it's just in case it would throw null;
- //make setter for name and ID
- a.setID(yml.getInt("id"));
- a.setName(yml.getString("name"));
- }
- }
Add Comment
Please, Sign In to add comment