/[projects]/miscJava/bukkit-minecraft-plugins/HoerupUtils/src/dk/thoerup/bukkit/hoeruputils/secretdoor/DoorStorage.java
ViewVC logotype

Diff of /miscJava/bukkit-minecraft-plugins/HoerupUtils/src/dk/thoerup/bukkit/hoeruputils/secretdoor/DoorStorage.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1603 by torben, Wed Jun 29 18:16:51 2011 UTC revision 1604 by torben, Tue Sep 27 18:27:54 2011 UTC
# Line 6  import java.io.IOException; Line 6  import java.io.IOException;
6  import java.io.RandomAccessFile;  import java.io.RandomAccessFile;
7  import java.util.HashMap;  import java.util.HashMap;
8  import java.util.LinkedList;  import java.util.LinkedList;
9    import java.util.List;
10    
11    import org.bukkit.util.config.Configuration;
12  import org.bukkit.Location;  import org.bukkit.Location;
13    import org.bukkit.World;
14  import org.bukkit.plugin.Plugin;  import org.bukkit.plugin.Plugin;
15    
16  public class DoorStorage {  public class DoorStorage {
# Line 37  public class DoorStorage { Line 40  public class DoorStorage {
40          }          }
41                    
42          public void saveAll() {          public void saveAll() {
                 try {  
43    
44                          File f = new File( plugin.getDataFolder(), "secretdoors.csv");                  File f2 = new File( plugin.getDataFolder(), "secretdoors.yml");
45                          RandomAccessFile out = new RandomAccessFile( f, "rw" );                  Configuration config = new Configuration(f2);
46                          out.setLength(0);        
47                    int count = 0;
48                          for (Door door : doors) {                  for (int i=0; i<doors.size(); i++) {
49                                  out.writeBytes( door.toCsv() );                          Door door = doors.get(i);
50                                  out.writeBytes( "\n");  
51                          }                          config.setProperty( i + ".world", door.getLeftUpper().getWorld().getName() );
52                            config.setProperty( i + ".x", door.getLeftUpper().getBlockX() );
53                          out.close();                          config.setProperty( i + ".y", door.getLeftUpper().getBlockY() );
54                  } catch (IOException e) {                          config.setProperty( i + ".z", door.getLeftUpper().getBlockZ() );
55                          System.out.println(e.getMessage() );                          config.setProperty( i + ".direction", door.getDirection()  );
56                          e.printStackTrace();                          config.setProperty( i + ".width", door.getWidth() );
57                            config.setProperty( i + ".height", door.getHeight() );
58                            config.setProperty( i + ".owner", door.getOwner() );
59                            
60    
61                  }                  }
62    
63    
64                    config.save();
65    
66          }          }
67    
68          public void loadAll() {          public void loadAll() {
69                  try {                  File f = new File( plugin.getDataFolder(), "secretdoors.yml");
70                          File f = new File( plugin.getDataFolder(), "secretdoors.csv");  
71                          RandomAccessFile in = new RandomAccessFile( f, "r" );                  if ( !f.exists() ) {
72                            System.out.println("[SecretDoor] coult not find secretdoors.yml");
                         String line;  
                         while ( (line = in.readLine() ) != null ) {  
                                 Door door = new Door(line, plugin.getServer() );                  
                                 doors.add( door );  
                                 door.registerMap( doormap );      
                         }  
                         in.close();  
                           
                         System.out.println("[SecretDoor] loaded " + doors.size() + " doors");  
                           
                 }  
                 catch (FileNotFoundException fnfe) {  
                         System.out.println("[SecretDoor] door file not found");  
73                          return;                          return;
74                  }                  }
75                  catch (IOException e) {                  Configuration config = new Configuration(f);
76                          System.out.println(e.getMessage() );                  config.load();
77                          e.printStackTrace();  
78                  }                  List<String> keys = config.getKeys(); //get all root keys
79    
80                            
81    
82                    for (String key : keys) {
83                            
84                            World world = plugin.getServer().getWorld( config.getString(key + ".world") );
85                            int x = config.getInt( key + ".x", 0);
86                            int y = config.getInt( key + ".y", 0);
87                            int z = config.getInt( key + ".z", 0);
88                            Location loc = new Location(world, x, y, z);
89                                    
90                            int direction = config.getInt( key + ".direction", 0);
91                            int width = config.getInt( key + ".width", 0);
92                            int height = config.getInt( key + ".height", 0);
93    
94                            String owner = config.getString( key + ".owner");
95                                    
96                            Door door = new Door(loc, direction, width, height, owner);
97                            doors.add( door );
98                            door.registerMap(doormap);
99                    }                      
100                            
101                    System.out.println("[SecretDoor] loaded " + doors.size() + " doors");
102                            
103          }          }
104    
105                    

Legend:
Removed from v.1603  
changed lines
  Added in v.1604

  ViewVC Help
Powered by ViewVC 1.1.20