/[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 2429 by torben, Sun Jan 13 13:05:16 2013 UTC revision 2430 by torben, Mon Mar 9 13:24:52 2015 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    
 import org.bukkit.Material;  
5  import org.bukkit.Location;  import org.bukkit.Location;
6  import org.bukkit.Server;  import org.bukkit.Material;
7  import org.bukkit.World;  import org.bukkit.World;
8  import org.bukkit.block.Block;  import org.bukkit.block.Block;
9    import org.bukkit.block.BlockFace;
10    import org.bukkit.block.BlockState;
11    
12    
13  class Door {  class Door {
14          final static int EAST = 0;  
         final static int WEST = 1;  
         final static int NORTH = 2;  
         final static int SOUTH = 3;  
           
15          private Location leftUpper;          private Location leftUpper;
16    
17                    
18          private Location blocks[][]; // [width][height] - [0][0] == leftUpper          private Location blockLocations[][]; // [width][height] - [0][0] == leftUpper
19          private int material[][];          private BlockState blockStates[][];
         private byte data[][];  
20                    
21          private int direction;          private BlockFace direction;
22                    
23          private int width;          private int width;
24          private int height;          private int height;
# Line 45  class Door { Line 41  class Door {
41                  this.isPrivate = isPrivate;                  this.isPrivate = isPrivate;
42                  this.password = password;                  this.password = password;
43                                    
44                    BlockState signState = sign.getState();
45                    org.bukkit.material.Sign signData = (org.bukkit.material.Sign) signState.getData();
46    
47                  direction = sign.getData() - 2;                  direction = signData.getFacing();
48                                    
49                  switch ( sign.getData() ) {                  switch ( direction ) {
50                  case 2: //facing east                  case EAST: //facing east
51                          leftUpper.setZ( leftUpper.getZ() + 1 );                          leftUpper.setZ( leftUpper.getZ() + 1 );
52                          break;                            break;  
53                  case 3: //facing west                  case WEST: //facing west
54                          leftUpper.setZ( leftUpper.getZ() - 1 );                          leftUpper.setZ( leftUpper.getZ() - 1 );
55                          break;                          break;
56                  case 4: //facing north                  case NORTH: //facing north
57                          leftUpper.setX( leftUpper.getX() + 1);                          leftUpper.setX( leftUpper.getX() + 1);
58                          break;                          break;
59                  case 5: //facing south                  case SOUTH: //facing south
60                          leftUpper.setX( leftUpper.getX() - 1);                          leftUpper.setX( leftUpper.getX() - 1);
61                          break;                          break;
62                    default:
63                            //DoNothing
64                            break;
65                  }                  }
66    
67                                    
# Line 72  class Door { Line 73  class Door {
73                    
74                  for (int w=0; w<width; w++) {                  for (int w=0; w<width; w++) {
75                          for (int h=0; h<height; h++) {                          for (int h=0; h<height; h++) {
76                                  Door d = store.findDoor( blocks[w][h] );                                  Door d = store.findDoor( blockLocations[w][h] );
77                                  if (d != null) {                                  if (d != null) {
78                                          throw new ConflictingDoorException();                                          throw new ConflictingDoorException();
79                                  }                                  }
# Line 100  class Door { Line 101  class Door {
101                  loadBlocks();                  loadBlocks();
102          }*/          }*/
103    
104          public Door(Location loc, int direction, int width, int height, String owner, boolean isPrivate, String password) {          public Door(Location loc, BlockFace direction, int width, int height, String owner, boolean isPrivate, String password) {
105                  leftUpper = loc;                  leftUpper = loc;
106                  this.direction = direction;                  this.direction = direction;
107                  this.width = width;                  this.width = width;
# Line 125  class Door { Line 126  class Door {
126          public boolean isPowered() {          public boolean isPowered() {
127                  for (int w=0; w<width; w++) {                  for (int w=0; w<width; w++) {
128                          for (int h=0; h<height; h++) {                          for (int h=0; h<height; h++) {
129                                  Block b = blocks[w][h].getBlock();                                  Block b = blockLocations[w][h].getBlock();
130    
131                                  if ( b.isBlockPowered() ||  b.isBlockIndirectlyPowered() )                                  if ( b.isBlockPowered() ||  b.isBlockIndirectlyPowered() )
132                                          return true;                                          return true;
# Line 136  class Door { Line 137  class Door {
137          }          }
138                    
139          private void loadBlocks() {          private void loadBlocks() {
140                  blocks = new Location[width][height];                            blockLocations = new Location[width][height];          
141                  material = new int[width][height];                                blockStates = new BlockState[width][height];            
                 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 165  class Door { Line 165  class Door {
165                                                                    
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);                                  blockLocations[w][h] = new Location( leftUpper.getWorld(), x, y, z);
169    
170                                  material[w][h] = blocks[w][h].getBlock().getTypeId();                                  blockStates[w][h] = blockLocations[w][h].getBlock().getState();
171                                  data[w][h] = blocks[w][h].getBlock().getData();          
                                   
172                          }                          }
173                  }                  }
174                                    
# Line 198  class Door { Line 197  class Door {
197          public void registerMap(Map<Location,Door> map) {          public void registerMap(Map<Location,Door> map) {
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                                  map.put(blocks[w][h], this);                                  map.put(blockLocations[w][h], this);
201                          }                          }
202                  }                  }
203          }          }
# Line 206  class Door { Line 205  class Door {
205          public void unregisterMap(Map<Location,Door> map) {          public void unregisterMap(Map<Location,Door> map) {
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                                  map.remove( blocks[w][h] );                                  map.remove( blockLocations[w][h] );
209                          }                          }
210                  }                  }
211    
# Line 216  class Door { Line 215  class Door {
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( 0, false);                                  //blocks[w][h].getBlock().setTypeId( 0, false);
218                                  blocks[w][h].getBlock().setType( Material.AIR );                                  blockLocations[w][h].getBlock().setType( Material.AIR );
219                          }                          }
220                  }                  }
221    
# Line 225  class Door { Line 224  class Door {
224          public void close() {          public void close() {
225                  for (int w=0; w<width; w++) {                  for (int w=0; w<width; w++) {
226                          for (int h=0; h<height; h++) {                                                    for (int h=0; h<height; h++) {                          
227                                  blocks[w][h].getBlock().setTypeIdAndData( material[w][h], data[w][h], true );                                  blockStates[w][h].update(true, true);
228                          }                          }
229                  }                  }
230          }          }
# Line 248  class Door { Line 247  class Door {
247                  return height;                  return height;
248          }          }
249    
250          public int getDirection() {          public BlockFace getDirection() {
251                  return direction;                  return direction;
252          }          }
253    

Legend:
Removed from v.2429  
changed lines
  Added in v.2430

  ViewVC Help
Powered by ViewVC 1.1.20