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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1604 - (show annotations) (download)
Tue Sep 27 18:27:54 2011 UTC (12 years, 7 months ago) by torben
File size: 2761 byte(s)
secretdoors now use yml for storage instead of csv
1 package dk.thoerup.bukkit.hoeruputils.secretdoor;
2
3 import java.io.File;
4 import java.io.FileNotFoundException;
5 import java.io.IOException;
6 import java.io.RandomAccessFile;
7 import java.util.HashMap;
8 import java.util.LinkedList;
9 import java.util.List;
10
11 import org.bukkit.util.config.Configuration;
12 import org.bukkit.Location;
13 import org.bukkit.World;
14 import org.bukkit.plugin.Plugin;
15
16 public class DoorStorage {
17 private HashMap<Location,Door> doormap = new HashMap<Location,Door>();
18 private LinkedList<Door> doors = new LinkedList<Door>();
19
20 private Plugin plugin;
21
22 public DoorStorage(Plugin plugin) {
23 this.plugin = plugin;
24 }
25
26 public Door findDoor(Location location) {
27 return doormap.get( location );
28 }
29
30 public void addDoor(Door door) {
31 door.registerMap(doormap);
32 doors.add(door);
33 saveAll();
34 }
35
36 public void removeDoor(Door door) {
37 door.unregisterMap(doormap);
38 doors.remove(door);
39 saveAll();
40 }
41
42 public void saveAll() {
43
44 File f2 = new File( plugin.getDataFolder(), "secretdoors.yml");
45 Configuration config = new Configuration(f2);
46
47 int count = 0;
48 for (int i=0; i<doors.size(); i++) {
49 Door door = doors.get(i);
50
51 config.setProperty( i + ".world", door.getLeftUpper().getWorld().getName() );
52 config.setProperty( i + ".x", door.getLeftUpper().getBlockX() );
53 config.setProperty( i + ".y", door.getLeftUpper().getBlockY() );
54 config.setProperty( i + ".z", door.getLeftUpper().getBlockZ() );
55 config.setProperty( i + ".direction", door.getDirection() );
56 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() {
69 File f = new File( plugin.getDataFolder(), "secretdoors.yml");
70
71 if ( !f.exists() ) {
72 System.out.println("[SecretDoor] coult not find secretdoors.yml");
73 return;
74 }
75 Configuration config = new Configuration(f);
76 config.load();
77
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
106
107 }

  ViewVC Help
Powered by ViewVC 1.1.20