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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1533 - (show annotations) (download)
Mon Jun 27 19:34:03 2011 UTC (12 years, 10 months ago) by torben
File size: 3266 byte(s)
add support for custom door sizes
1 package dk.thoerup.bukkit.hoeruputils.secretdoor;
2
3 import java.util.Map;
4
5 import org.bukkit.Location;
6 import org.bukkit.Server;
7 import org.bukkit.World;
8 import org.bukkit.block.Block;
9
10
11 class Door {
12 final static int EAST = 0;
13 final static int WEST = 1;
14 final static int NORTH = 2;
15 final static int SOUTH = 3;
16
17 Location leftUpper;
18
19
20 Location blocks[][]; // [width][height] - [0][0] == leftUpper
21
22 int material;
23
24 int direction;
25
26 int width;
27 int height;
28
29
30 public Door(Block sign, int width, int height) {
31 leftUpper = sign.getLocation().clone();
32
33 this.width = width;
34 this.height = height;
35
36 blocks = new Location[width][height];
37
38 direction = sign.getData() - 2;
39
40 switch ( sign.getData() ) {
41 case 2: //facing east
42 leftUpper.setZ( leftUpper.getZ() + 1 );
43 break;
44 case 3: //facing west
45 leftUpper.setZ( leftUpper.getZ() - 1 );
46 break;
47 case 4: //facing north
48 leftUpper.setX( leftUpper.getX() + 1);
49 break;
50 case 5: //facing south
51 leftUpper.setX( leftUpper.getX() - 1);
52 break;
53 }
54
55
56
57 material = leftUpper.getBlock().getTypeId();
58
59 loadBlocks();
60
61 }
62
63 public Door(String input, Server server) {
64 String parts[] = input.split(":");
65
66 World w = server.getWorld( parts[0] );
67
68 leftUpper = new Location(w, Integer.parseInt(parts[1]), Integer.parseInt(parts[2]), Integer.parseInt(parts[3]) );
69 direction = Integer.parseInt( parts[4] );
70 material = Integer.parseInt( parts[5] );
71
72 width = Integer.parseInt( parts[6] );
73 height = Integer.parseInt( parts[7] );
74
75 loadBlocks();
76 }
77
78 private void loadBlocks() {
79
80 for (int w=0; w<width; w++) {
81 for (int h=0; h<height; h++) {
82 int x = leftUpper.getBlockX();
83 int y = leftUpper.getBlockY();
84 int z = leftUpper.getBlockZ();
85 switch(direction) {
86 case EAST:
87 x -= w;
88 break;
89 case WEST:
90 x += w;
91 break;
92 case NORTH:
93 z += w;
94 break;
95 case SOUTH:
96 z -= w;
97 break;
98 default:
99 System.out.println("[SecretDoor] this should never happen");
100 }
101 y -= h;
102
103 //System.out.println("Add block: " + x + ":" + y + ":" + z);
104
105 blocks[w][h] = new Location( leftUpper.getWorld(), x, y, z);
106
107 }
108 }
109
110 }
111
112 public String toCsv() {
113 StringBuilder sb = new StringBuilder();
114 sb.append( leftUpper.getWorld().getName() );
115
116 sb.append( ":" + leftUpper.getBlockX() );
117 sb.append( ":" + leftUpper.getBlockY() );
118 sb.append( ":" + leftUpper.getBlockZ() );
119
120 sb.append( ":" + direction );
121
122 sb.append( ":" + material );
123
124 sb.append( ":" + width );
125 sb.append( ":" + height );
126
127 return sb.toString();
128 }
129
130
131 public void registerMap(Map<Location,Door> map) {
132 for (int w=0; w<width; w++) {
133 for (int h=0; h<height; h++) {
134 map.put(blocks[w][h], this);
135 }
136 }
137 }
138
139 public void unregisterMap(Map<Location,Door> map) {
140 for (int w=0; w<width; w++) {
141 for (int h=0; h<height; h++) {
142 map.remove( blocks[w][h] );
143 }
144 }
145
146 }
147
148 public void open(World world) {
149 for (int w=0; w<width; w++) {
150 for (int h=0; h<height; h++) {
151 blocks[w][h].getBlock().setTypeId(0);
152 }
153 }
154
155 }
156
157 public void close(World world) {
158 for (int w=0; w<width; w++) {
159 for (int h=0; h<height; h++) {
160 blocks[w][h].getBlock().setTypeId( material );
161 }
162 }
163 }
164
165 }

  ViewVC Help
Powered by ViewVC 1.1.20