18 |
|
|
19 |
|
|
20 |
private Location blocks[][]; // [width][height] - [0][0] == leftUpper |
private Location blocks[][]; // [width][height] - [0][0] == leftUpper |
21 |
|
private int material[][]; |
22 |
private int material; |
private byte data[][]; |
23 |
|
|
24 |
private int direction; |
private int direction; |
25 |
|
|
27 |
private int height; |
private int height; |
28 |
|
|
29 |
private String owner; |
private String owner; |
30 |
|
|
31 |
|
private boolean isPrivate; |
32 |
|
|
33 |
|
|
34 |
public Door(Block sign, int width, int height, DoorStorage store, String owner) throws ConflictingDoorException{ |
public Door(Block sign, int width, int height, DoorStorage store, String owner, boolean isPrivate) throws ConflictingDoorException{ |
35 |
leftUpper = sign.getLocation().clone(); |
leftUpper = sign.getLocation().clone(); |
36 |
|
|
37 |
this.width = width; |
this.width = width; |
38 |
this.height = height; |
this.height = height; |
39 |
|
|
40 |
this.owner = owner; |
this.owner = owner; |
41 |
|
|
42 |
|
this.isPrivate = isPrivate; |
43 |
|
|
|
blocks = new Location[width][height]; |
|
44 |
|
|
45 |
direction = sign.getData() - 2; |
direction = sign.getData() - 2; |
46 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
material = leftUpper.getBlock().getTypeId(); |
//material = leftUpper.getBlock().getTypeId(); |
65 |
|
|
66 |
loadBlocks(); |
loadBlocks(); |
67 |
|
|
68 |
|
|
69 |
for (int w=0; w<width; w++) { |
for (int w=0; w<width; w++) { |
70 |
for (int h=0; h<height; h++) { |
for (int h=0; h<height; h++) { |
71 |
Door d = store.findDoor( blocks[w][h] ); |
Door d = store.findDoor( blocks[w][h] ); |
77 |
|
|
78 |
} |
} |
79 |
|
|
80 |
|
/* |
81 |
|
@Deprecated |
82 |
public Door(String input, Server server) { |
public Door(String input, Server server) { |
83 |
String parts[] = input.split(":"); |
String parts[] = input.split(":"); |
84 |
|
|
86 |
|
|
87 |
leftUpper = new Location(w, Integer.parseInt(parts[1]), Integer.parseInt(parts[2]), Integer.parseInt(parts[3]) ); |
leftUpper = new Location(w, Integer.parseInt(parts[1]), Integer.parseInt(parts[2]), Integer.parseInt(parts[3]) ); |
88 |
direction = Integer.parseInt( parts[4] ); |
direction = Integer.parseInt( parts[4] ); |
89 |
material = Integer.parseInt( parts[5] ); |
//material = Integer.parseInt( parts[5] ); |
90 |
|
|
91 |
width = Integer.parseInt( parts[6] ); |
width = Integer.parseInt( parts[6] ); |
92 |
height = Integer.parseInt( parts[7] ); |
height = Integer.parseInt( parts[7] ); |
93 |
owner = parts[8]; |
owner = parts[8]; |
94 |
|
|
|
|
|
|
blocks = new Location[width][height]; |
|
95 |
|
|
96 |
loadBlocks(); |
loadBlocks(); |
97 |
|
}*/ |
98 |
|
|
99 |
|
public Door(Location loc, int direction, int width, int height, String owner, boolean isPrivate) { |
100 |
|
leftUpper = loc; |
101 |
|
this.direction = direction; |
102 |
|
this.width = width; |
103 |
|
this.height = height; |
104 |
|
this.owner = owner; |
105 |
|
this.isPrivate = isPrivate; |
106 |
|
|
107 |
|
loadBlocks(); |
108 |
|
} |
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
public void powerChange(World world, int oldCurrent, int newCurrent ) { |
113 |
|
if (isPowered() == true) { |
114 |
|
open(); |
115 |
|
} else { |
116 |
|
close(); |
117 |
|
} |
118 |
|
} |
119 |
|
|
120 |
|
public boolean isPowered() { |
121 |
|
for (int w=0; w<width; w++) { |
122 |
|
for (int h=0; h<height; h++) { |
123 |
|
Block b = blocks[w][h].getBlock(); |
124 |
|
|
125 |
|
if ( b.isBlockPowered() || b.isBlockIndirectlyPowered() ) |
126 |
|
return true; |
127 |
|
} |
128 |
|
} |
129 |
|
|
130 |
|
return false; |
131 |
} |
} |
132 |
|
|
133 |
private void loadBlocks() { |
private void loadBlocks() { |
134 |
|
blocks = new Location[width][height]; |
135 |
|
material = new int[width][height]; |
136 |
|
data = new byte[width][height]; |
137 |
|
|
138 |
for (int w=0; w<width; w++) { |
for (int w=0; w<width; w++) { |
139 |
for (int h=0; h<height; h++) { |
for (int h=0; h<height; h++) { |
161 |
//System.out.println("Add block: " + x + ":" + y + ":" + z); |
//System.out.println("Add block: " + x + ":" + y + ":" + z); |
162 |
|
|
163 |
blocks[w][h] = new Location( leftUpper.getWorld(), x, y, z); |
blocks[w][h] = new Location( leftUpper.getWorld(), x, y, z); |
164 |
|
|
165 |
|
material[w][h] = blocks[w][h].getBlock().getTypeId(); |
166 |
|
data[w][h] = blocks[w][h].getBlock().getData(); |
167 |
|
|
168 |
} |
} |
169 |
} |
} |
170 |
|
|
171 |
} |
} |
172 |
|
|
173 |
public String toCsv() { |
/* public String toCsv() { |
174 |
StringBuilder sb = new StringBuilder(); |
StringBuilder sb = new StringBuilder(); |
175 |
sb.append( leftUpper.getWorld().getName() ); |
sb.append( leftUpper.getWorld().getName() ); |
176 |
|
|
180 |
|
|
181 |
sb.append( ":" + direction ); |
sb.append( ":" + direction ); |
182 |
|
|
183 |
sb.append( ":" + material ); |
sb.append( ":" + material[0][0] ); |
184 |
|
|
185 |
sb.append( ":" + width ); |
sb.append( ":" + width ); |
186 |
sb.append( ":" + height ); |
sb.append( ":" + height ); |
187 |
sb.append( ":" + owner); |
sb.append( ":" + owner); |
188 |
|
|
189 |
return sb.toString(); |
return sb.toString(); |
190 |
} |
}*/ |
191 |
|
|
192 |
|
|
193 |
public void registerMap(Map<Location,Door> map) { |
public void registerMap(Map<Location,Door> map) { |
207 |
|
|
208 |
} |
} |
209 |
|
|
210 |
public void open(World world) { |
public void open() { |
211 |
for (int w=0; w<width; w++) { |
for (int w=0; w<width; w++) { |
212 |
for (int h=0; h<height; h++) { |
for (int h=0; h<height; h++) { |
213 |
blocks[w][h].getBlock().setTypeId(0); |
blocks[w][h].getBlock().setTypeId(0, false); |
214 |
} |
} |
215 |
} |
} |
216 |
|
|
217 |
} |
} |
218 |
|
|
219 |
public void close(World world) { |
public void close() { |
220 |
for (int w=0; w<width; w++) { |
for (int w=0; w<width; w++) { |
221 |
for (int h=0; h<height; h++) { |
for (int h=0; h<height; h++) { |
222 |
blocks[w][h].getBlock().setTypeId( material ); |
blocks[w][h].getBlock().setTypeIdAndData( material[w][h], data[w][h], true ); |
223 |
} |
} |
224 |
} |
} |
225 |
} |
} |
230 |
return owner; |
return owner; |
231 |
} |
} |
232 |
|
|
233 |
|
public Location getLeftUpper() { |
234 |
|
return leftUpper; |
235 |
|
} |
236 |
|
|
237 |
|
public int getWidth() { |
238 |
|
return width; |
239 |
|
} |
240 |
|
|
241 |
|
public int getHeight() { |
242 |
|
return height; |
243 |
|
} |
244 |
|
|
245 |
|
public int getDirection() { |
246 |
|
return direction; |
247 |
|
} |
248 |
|
|
249 |
|
public boolean isPrivate() { |
250 |
|
return isPrivate; |
251 |
|
} |
252 |
|
|
253 |
} |
} |