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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1912 - (hide annotations) (download)
Sun Jan 13 13:05:16 2013 UTC (11 years, 4 months ago) by torben
File size: 3258 byte(s)
First try at opening doors with passwords
1 torben 1530 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 torben 1614 import java.util.Set;
10 torben 1530
11 torben 1614 import org.bukkit.configuration.file.YamlConfiguration;
12 torben 1530 import org.bukkit.Location;
13 torben 1604 import org.bukkit.World;
14 torben 1530 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 torben 1538 private Plugin plugin;
21 torben 1530
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 torben 1604 File f2 = new File( plugin.getDataFolder(), "secretdoors.yml");
45 torben 1614 YamlConfiguration config = new YamlConfiguration();
46 torben 1530
47 torben 1912
48 torben 1604 for (int i=0; i<doors.size(); i++) {
49     Door door = doors.get(i);
50 torben 1530
51 torben 1614 config.set( i + ".world", door.getLeftUpper().getWorld().getName() );
52     config.set( i + ".x", door.getLeftUpper().getBlockX() );
53     config.set( i + ".y", door.getLeftUpper().getBlockY() );
54     config.set( i + ".z", door.getLeftUpper().getBlockZ() );
55     config.set( i + ".direction", door.getDirection() );
56     config.set( i + ".width", door.getWidth() );
57     config.set( i + ".height", door.getHeight() );
58     config.set( i + ".owner", door.getOwner() );
59 torben 1912 config.set( i + ".private", door.isPrivate() );
60     config.set( i + ".password", door.getPassword() );
61 torben 1530 }
62 torben 1604
63 torben 1614 try {
64     config.save(f2);
65     } catch (java.io.IOException e) {
66     System.out.println("[SecretDoor] DoorStorage : exception saving doors : " + e.getMessage() );
67     }
68 torben 1604
69 torben 1530 }
70    
71     public void loadAll() {
72 torben 1604 File f = new File( plugin.getDataFolder(), "secretdoors.yml");
73 torben 1530
74 torben 1604 if ( !f.exists() ) {
75     System.out.println("[SecretDoor] coult not find secretdoors.yml");
76     return;
77     }
78 torben 1614 YamlConfiguration config = new YamlConfiguration();
79     try {
80     config.load(f);
81     } catch (Exception e) {
82     System.out.println("[SecretDoor] DoorStorage: exception loading doors : " + e.getMessage() );
83     return;
84     }
85 torben 1604
86 torben 1614 Set<String> keys = config.getKeys(false); //get all root keys
87 torben 1604
88 torben 1530
89 torben 1604
90     for (String key : keys) {
91 torben 1532
92 torben 1604 World world = plugin.getServer().getWorld( config.getString(key + ".world") );
93     int x = config.getInt( key + ".x", 0);
94     int y = config.getInt( key + ".y", 0);
95     int z = config.getInt( key + ".z", 0);
96     Location loc = new Location(world, x, y, z);
97    
98     int direction = config.getInt( key + ".direction", 0);
99     int width = config.getInt( key + ".width", 0);
100     int height = config.getInt( key + ".height", 0);
101    
102     String owner = config.getString( key + ".owner");
103 torben 1605
104     boolean isPrivate = config.getBoolean( key + ".private", false);
105 torben 1912 String password = config.getString( key + ".password", "");
106 torben 1604
107 torben 1912 Door door = new Door(loc, direction, width, height, owner, isPrivate, password);
108 torben 1604 doors.add( door );
109     door.registerMap(doormap);
110     }
111    
112     System.out.println("[SecretDoor] loaded " + doors.size() + " doors");
113    
114 torben 1530 }
115    
116    
117    
118     }

  ViewVC Help
Powered by ViewVC 1.1.20