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

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

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

revision 1534 by torben, Mon Jun 27 19:43:33 2011 UTC revision 1604 by torben, Tue Sep 27 18:27:54 2011 UTC
# Line 14  class Door { Line 14  class Door {
14          final static int NORTH = 2;          final static int NORTH = 2;
15          final static int SOUTH = 3;          final static int SOUTH = 3;
16                    
17          Location leftUpper;          private Location leftUpper;
18    
19                    
20          Location blocks[][]; // [width][height] - [0][0] == leftUpper          private Location blocks[][]; // [width][height] - [0][0] == leftUpper
21            private int material[][];
22          int material;          private byte data[][];
23                    
24          int direction;          private int direction;
25                    
26          int width;          private int width;
27          int height;          private int height;
28    
29            private String owner;
30                    
31    
32          public Door(Block sign, int width, int height, DoorStorage store) throws ConflictingDoorException{          public Door(Block sign, int width, int height, DoorStorage store, String owner) throws ConflictingDoorException{
33                  leftUpper = sign.getLocation().clone();                  leftUpper = sign.getLocation().clone();
34                                    
35                  this.width = width;                  this.width = width;
36                  this.height = height;                  this.height = height;
37    
38                    this.owner = owner;
39                                    
                 blocks = new Location[width][height];            
40    
41                  direction = sign.getData() - 2;                  direction = sign.getData() - 2;
42                                    
# Line 54  class Door { Line 57  class Door {
57    
58                                    
59                                    
60                  material = leftUpper.getBlock().getTypeId();                  //material = leftUpper.getBlock().getTypeId();
61                                    
62                  loadBlocks();                  loadBlocks();
63                                    
64                            
65                  for (int w=0; w<width; w++) {                  for (int w=0; w<width; w++) {
66                          for (int h=0; h<height; h++) {                          for (int h=0; h<height; h++) {
67                                  Door d = store.findDoor( blocks[w][h] );                                  Door d = store.findDoor( blocks[w][h] );
# Line 70  class Door { Line 73  class Door {
73    
74          }          }
75    
76    /*
77            @Deprecated
78          public Door(String input, Server server) {          public Door(String input, Server server) {
79                  String parts[] = input.split(":");                  String parts[] = input.split(":");
80    
# Line 77  class Door { Line 82  class Door {
82    
83                  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]) );
84                  direction = Integer.parseInt( parts[4] );                  direction = Integer.parseInt( parts[4] );
85                  material = Integer.parseInt( parts[5] );                  //material = Integer.parseInt( parts[5] );
86                                    
87                  width = Integer.parseInt( parts[6] );                  width = Integer.parseInt( parts[6] );
88                  height = Integer.parseInt( parts[7] );                  height = Integer.parseInt( parts[7] );
89                    owner = parts[8];
90    
91                                    
92                  loadBlocks();                  loadBlocks();
93            }*/
94    
95            public Door(Location loc, int direction, int width, int height, String owner) {
96                    leftUpper = loc;
97                    this.direction = direction;
98                    this.width = width;
99                    this.height = height;
100                    this.owner = owner;
101    
102                    loadBlocks();
103            }
104    
105            
106    
107            public void powerChange(World world, int oldCurrent, int newCurrent ) {
108                    if (isPowered() == true) {
109                            open();
110                    } else {
111                            close();
112                    }      
113            }
114    
115            public boolean isPowered() {
116                    for (int w=0; w<width; w++) {
117                            for (int h=0; h<height; h++) {
118                                    Block b = blocks[w][h].getBlock();
119    
120                                    if ( b.isBlockPowered() ||  b.isBlockIndirectlyPowered() )
121                                            return true;
122                            }
123                    }
124                            
125                    return false;
126          }          }
127                    
128          private void loadBlocks() {          private void loadBlocks() {
129                    blocks = new Location[width][height];          
130                    material = new int[width][height];              
131                    data = new byte[width][height];        
132                                    
133                  for (int w=0; w<width; w++) {                  for (int w=0; w<width; w++) {
134                          for (int h=0; h<height; h++) {                          for (int h=0; h<height; h++) {
# Line 113  class Door { Line 156  class Door {
156                                  //System.out.println("Add block: " + x + ":" + y + ":" + z);                                  //System.out.println("Add block: " + x + ":" + y + ":" + z);
157                                                                    
158                                  blocks[w][h] = new Location( leftUpper.getWorld(), x, y, z);                                  blocks[w][h] = new Location( leftUpper.getWorld(), x, y, z);
159    
160                                    material[w][h] = blocks[w][h].getBlock().getTypeId();
161                                    data[w][h] = blocks[w][h].getBlock().getData();
162                                                                    
163                          }                          }
164                  }                  }
165                                    
166          }          }
167    
168          public String toCsv() {  /*      public String toCsv() {
169                  StringBuilder sb = new StringBuilder();                  StringBuilder sb = new StringBuilder();
170                  sb.append( leftUpper.getWorld().getName() );                  sb.append( leftUpper.getWorld().getName() );
171    
# Line 129  class Door { Line 175  class Door {
175                                    
176                  sb.append( ":" + direction );                  sb.append( ":" + direction );
177    
178                  sb.append( ":" + material );                  sb.append( ":" + material[0][0] );
179                                    
180                  sb.append( ":" + width );                  sb.append( ":" + width );
181                  sb.append( ":" + height );                  sb.append( ":" + height );
182                    sb.append( ":" + owner);
183    
184                  return sb.toString();                  return sb.toString();
185          }          }*/
186    
187    
188          public void registerMap(Map<Location,Door> map) {          public void registerMap(Map<Location,Door> map) {
# Line 155  class Door { Line 202  class Door {
202    
203          }          }
204    
205          public void open(World world) {          public void open() {
206                  for (int w=0; w<width; w++) {                  for (int w=0; w<width; w++) {
207                          for (int h=0; h<height; h++) {                                                    for (int h=0; h<height; h++) {                          
208                                  blocks[w][h].getBlock().setTypeId(0);                                  blocks[w][h].getBlock().setTypeId(0, false);
209                          }                          }
210                  }                  }
211    
212          }          }
213    
214          public void close(World world) {          public void close() {
215                  for (int w=0; w<width; w++) {                  for (int w=0; w<width; w++) {
216                          for (int h=0; h<height; h++) {                                                    for (int h=0; h<height; h++) {                          
217                                  blocks[w][h].getBlock().setTypeId( material );                                  blocks[w][h].getBlock().setTypeIdAndData( material[w][h], data[w][h], true );
218                          }                          }
219                  }                  }
220          }          }
221    
 }  
222    
223            /////// setters and getters
224            public String getOwner() {
225                    return owner;
226            }
227    
228            public Location getLeftUpper() {
229                    return leftUpper;
230            }
231    
232            public int getWidth() {
233                    return width;
234            }
235    
236            public int getHeight() {
237                    return height;
238            }
239    
240            public int getDirection() {
241                    return direction;
242            }
243    
244    }

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

  ViewVC Help
Powered by ViewVC 1.1.20