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

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

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

revision 1533 by torben, Mon Jun 27 19:34:03 2011 UTC revision 1580 by torben, Sun Jul 17 19:28:22 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    
22          int material;          private int material;
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) {          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                                    
40                  blocks = new Location[width][height];                            blocks = new Location[width][height];          
41    
# Line 57  class Door { Line 61  class Door {
61                  material = leftUpper.getBlock().getTypeId();                  material = leftUpper.getBlock().getTypeId();
62                                    
63                  loadBlocks();                  loadBlocks();
64                    
65            
66                    for (int w=0; w<width; w++) {
67                            for (int h=0; h<height; h++) {
68                                    Door d = store.findDoor( blocks[w][h] );
69                                    if (d != null) {
70                                            throw new ConflictingDoorException();
71                                    }
72                            }
73                    }
74    
75          }          }
76    
# Line 71  class Door { Line 85  class Door {
85                                    
86                  width = Integer.parseInt( parts[6] );                  width = Integer.parseInt( parts[6] );
87                  height = Integer.parseInt( parts[7] );                  height = Integer.parseInt( parts[7] );
88                    owner = parts[8];
89    
90    
91                    blocks = new Location[width][height];          
92                                    
93                  loadBlocks();                  loadBlocks();
94          }          }
95    
96            public void powerChange(World world, int oldCurrent, int newCurrent ) {
97                    if (isPowered() == true) {
98                            open();
99                    } else {
100                            close();
101                    }      
102            }
103    
104            public boolean isPowered() {
105                    for (int w=0; w<width; w++) {
106                            for (int h=0; h<height; h++) {
107                                    Block b = blocks[w][h].getBlock();
108    
109                                    if ( b.isBlockPowered() ||  b.isBlockIndirectlyPowered() )
110                                            return true;
111                            }
112                    }
113                            
114                    return false;
115            }
116                    
117          private void loadBlocks() {          private void loadBlocks() {
118                                    
# Line 123  class Door { Line 162  class Door {
162                                    
163                  sb.append( ":" + width );                  sb.append( ":" + width );
164                  sb.append( ":" + height );                  sb.append( ":" + height );
165                    sb.append( ":" + owner);
166    
167                  return sb.toString();                  return sb.toString();
168          }          }
# Line 145  class Door { Line 185  class Door {
185    
186          }          }
187    
188          public void open(World world) {          public void open() {
189                  for (int w=0; w<width; w++) {                  for (int w=0; w<width; w++) {
190                          for (int h=0; h<height; h++) {                                                    for (int h=0; h<height; h++) {                          
191                                  blocks[w][h].getBlock().setTypeId(0);                                  blocks[w][h].getBlock().setTypeId(0, false);
192                          }                          }
193                  }                  }
194    
195          }          }
196    
197          public void close(World world) {          public void close() {
198                  for (int w=0; w<width; w++) {                  for (int w=0; w<width; w++) {
199                          for (int h=0; h<height; h++) {                                                    for (int h=0; h<height; h++) {                          
200                                  blocks[w][h].getBlock().setTypeId( material );                                  blocks[w][h].getBlock().setTypeId( material );
# Line 162  class Door { Line 202  class Door {
202                  }                  }
203          }          }
204    
 }  
205    
206            /////// setters and getters
207            public String getOwner() {
208                    return owner;
209            }
210    
211    }

Legend:
Removed from v.1533  
changed lines
  Added in v.1580

  ViewVC Help
Powered by ViewVC 1.1.20