/[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

miscJava/bukkit-minecraft-plugins/HoerupUtils/src/dk/thoerup/bukkit/hoeruputils/secretdoor/Door.java revision 1536 by torben, Wed Jun 29 17:19:38 2011 UTC miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/secretdoor/Door.java revision 1912 by torben, Sun Jan 13 13:05:16 2013 UTC
# Line 2  package dk.thoerup.bukkit.hoeruputils.se Line 2  package dk.thoerup.bukkit.hoeruputils.se
2    
3  import java.util.Map;  import java.util.Map;
4    
5    import org.bukkit.Material;
6  import org.bukkit.Location;  import org.bukkit.Location;
7  import org.bukkit.Server;  import org.bukkit.Server;
8  import org.bukkit.World;  import org.bukkit.World;
# Line 14  class Door { Line 15  class Door {
15          final static int NORTH = 2;          final static int NORTH = 2;
16          final static int SOUTH = 3;          final static int SOUTH = 3;
17                    
18          Location leftUpper;          private Location leftUpper;
19    
20                    
21          Location blocks[][]; // [width][height] - [0][0] == leftUpper          private Location blocks[][]; // [width][height] - [0][0] == leftUpper
22            private int material[][];
23          int material;          private byte data[][];
24                    
25          int direction;          private int direction;
26                    
27          int width;          private int width;
28          int height;          private int height;
29    
30            private String owner;
31    
32          String owner;          private boolean isPrivate;
33            
34            private String password;
35                    
36    
37          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, String password) throws ConflictingDoorException{
38                  leftUpper = sign.getLocation().clone();                  leftUpper = sign.getLocation().clone();
39                                    
40                  this.width = width;                  this.width = width;
41                  this.height = height;                  this.height = height;
42    
43                  this.owner = owner;                  this.owner = owner;
44    
45                    this.isPrivate = isPrivate;
46                    this.password = password;
47                                    
                 blocks = new Location[width][height];            
48    
49                  direction = sign.getData() - 2;                  direction = sign.getData() - 2;
50                                    
# Line 58  class Door { Line 65  class Door {
65    
66                                    
67                                    
68                  material = leftUpper.getBlock().getTypeId();                  //material = leftUpper.getBlock().getTypeId();
69                                    
70                  loadBlocks();                  loadBlocks();
71                                    
72                            
73                  for (int w=0; w<width; w++) {                  for (int w=0; w<width; w++) {
74                          for (int h=0; h<height; h++) {                          for (int h=0; h<height; h++) {
75                                  Door d = store.findDoor( blocks[w][h] );                                  Door d = store.findDoor( blocks[w][h] );
# Line 74  class Door { Line 81  class Door {
81    
82          }          }
83    
84    /*
85            @Deprecated
86          public Door(String input, Server server) {          public Door(String input, Server server) {
87                  String parts[] = input.split(":");                  String parts[] = input.split(":");
88    
# Line 81  class Door { Line 90  class Door {
90    
91                  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]) );
92                  direction = Integer.parseInt( parts[4] );                  direction = Integer.parseInt( parts[4] );
93                  material = Integer.parseInt( parts[5] );                  //material = Integer.parseInt( parts[5] );
94                                    
95                  width = Integer.parseInt( parts[6] );                  width = Integer.parseInt( parts[6] );
96                  height = Integer.parseInt( parts[7] );                  height = Integer.parseInt( parts[7] );
97                  owner = parts[8];                  owner = parts[8];
98    
   
                 blocks = new Location[width][height];            
99                                    
100                  loadBlocks();                  loadBlocks();
101            }*/
102    
103            public Door(Location loc, int direction, int width, int height, String owner, boolean isPrivate, String password) {
104                    leftUpper = loc;
105                    this.direction = direction;
106                    this.width = width;
107                    this.height = height;
108                    this.owner = owner;
109                    this.isPrivate = isPrivate;
110                    this.password = password;
111    
112                    loadBlocks();
113            }
114    
115            
116    
117            public void powerChange(World world, int oldCurrent, int newCurrent ) {
118                    if (isPowered() == true) {
119                            open();
120                    } else {
121                            close();
122                    }      
123            }
124    
125            public boolean isPowered() {
126                    for (int w=0; w<width; w++) {
127                            for (int h=0; h<height; h++) {
128                                    Block b = blocks[w][h].getBlock();
129    
130                                    if ( b.isBlockPowered() ||  b.isBlockIndirectlyPowered() )
131                                            return true;
132                            }
133                    }
134                            
135                    return false;
136          }          }
137                    
138          private void loadBlocks() {          private void loadBlocks() {
139                    blocks = new Location[width][height];          
140                    material = new int[width][height];              
141                    data = new byte[width][height];        
142                                    
143                  for (int w=0; w<width; w++) {                  for (int w=0; w<width; w++) {
144                          for (int h=0; h<height; h++) {                          for (int h=0; h<height; h++) {
# Line 121  class Door { Line 166  class Door {
166                                  //System.out.println("Add block: " + x + ":" + y + ":" + z);                                  //System.out.println("Add block: " + x + ":" + y + ":" + z);
167                                                                    
168                                  blocks[w][h] = new Location( leftUpper.getWorld(), x, y, z);                                  blocks[w][h] = new Location( leftUpper.getWorld(), x, y, z);
169    
170                                    material[w][h] = blocks[w][h].getBlock().getTypeId();
171                                    data[w][h] = blocks[w][h].getBlock().getData();
172                                                                    
173                          }                          }
174                  }                  }
175                                    
176          }          }
177    
178          public String toCsv() {  /*      public String toCsv() {
179                  StringBuilder sb = new StringBuilder();                  StringBuilder sb = new StringBuilder();
180                  sb.append( leftUpper.getWorld().getName() );                  sb.append( leftUpper.getWorld().getName() );
181    
# Line 137  class Door { Line 185  class Door {
185                                    
186                  sb.append( ":" + direction );                  sb.append( ":" + direction );
187    
188                  sb.append( ":" + material );                  sb.append( ":" + material[0][0] );
189                                    
190                  sb.append( ":" + width );                  sb.append( ":" + width );
191                  sb.append( ":" + height );                  sb.append( ":" + height );
192                  sb.append( ":" + owner);                  sb.append( ":" + owner);
193    
194                  return sb.toString();                  return sb.toString();
195          }          }*/
196    
197    
198          public void registerMap(Map<Location,Door> map) {          public void registerMap(Map<Location,Door> map) {
# Line 164  class Door { Line 212  class Door {
212    
213          }          }
214    
215          public void open(World world) {          public void open() {
216                  for (int w=0; w<width; w++) {                  for (int w=0; w<width; w++) {
217                          for (int h=0; h<height; h++) {                                                    for (int h=0; h<height; h++) {                          
218                                  blocks[w][h].getBlock().setTypeId(0);                                  //blocks[w][h].getBlock().setTypeId( 0, false);
219                                    blocks[w][h].getBlock().setType( Material.AIR );
220                          }                          }
221                  }                  }
222    
223          }          }
224    
225          public void close(World world) {          public void close() {
226                  for (int w=0; w<width; w++) {                  for (int w=0; w<width; w++) {
227                          for (int h=0; h<height; h++) {                                                    for (int h=0; h<height; h++) {                          
228                                  blocks[w][h].getBlock().setTypeId( material );                                  blocks[w][h].getBlock().setTypeIdAndData( material[w][h], data[w][h], true );
229                          }                          }
230                  }                  }
231          }          }
232    
233    
234            /////// setters and getters
235            public String getOwner() {
236                    return owner;
237            }
238    
239            public Location getLeftUpper() {
240                    return leftUpper;
241            }
242    
243            public int getWidth() {
244                    return width;
245            }
246    
247            public int getHeight() {
248                    return height;
249            }
250    
251            public int getDirection() {
252                    return direction;
253            }
254    
255            public boolean isPrivate() {
256                    return isPrivate;
257            }
258            
259            public String getPassword() {
260                    return password;
261            }
262    
263  }  }

Legend:
Removed from v.1536  
changed lines
  Added in v.1912

  ViewVC Help
Powered by ViewVC 1.1.20