Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
Gate.java
1 package org.bukkit.material;
2 
3 import org.bukkit.Material;
5 
6 /**
7  * Represents a fence gate
8  */
9 public class Gate extends MaterialData implements Directional, Openable {
10  private static final byte OPEN_BIT = 0x4;
11  private static final byte DIR_BIT = 0x3;
12  private static final byte GATE_SOUTH = 0x0;
13  private static final byte GATE_WEST = 0x1;
14  private static final byte GATE_NORTH = 0x2;
15  private static final byte GATE_EAST = 0x3;
16 
17  public Gate() {
18  super(Material.FENCE_GATE);
19  }
20 
21  public Gate(int type, byte data){
22  super(type, data);
23  }
24 
25  public Gate(byte data) {
26  super(Material.FENCE_GATE, data);
27  }
28 
29  public void setFacingDirection(BlockFace face) {
30  byte data = (byte) (getData() &~ DIR_BIT);
31 
32  switch (face) {
33  default:
34  case EAST:
35  data |= GATE_SOUTH;
36  break;
37  case SOUTH:
38  data |= GATE_WEST;
39  break;
40  case WEST:
41  data |= GATE_NORTH;
42  break;
43  case NORTH:
44  data |= GATE_EAST;
45  break;
46  }
47 
48  setData(data);
49  }
50 
51  public BlockFace getFacing() {
52  switch (getData() & DIR_BIT) {
53  case GATE_SOUTH:
54  return BlockFace.EAST;
55  case GATE_WEST:
56  return BlockFace.SOUTH;
57  case GATE_NORTH:
58  return BlockFace.WEST;
59  case GATE_EAST:
60  return BlockFace.NORTH;
61  }
62 
63  return BlockFace.EAST;
64  }
65 
66  public boolean isOpen() {
67  return (getData() & OPEN_BIT) > 0;
68  }
69 
70  public void setOpen(boolean isOpen) {
71  byte data = getData();
72 
73  if (isOpen) {
74  data |= OPEN_BIT;
75  } else {
76  data &= ~OPEN_BIT;
77  }
78 
79  setData(data);
80  }
81 
82  @Override
83  public String toString() {
84  return (isOpen() ? "OPEN " : "CLOSED ") + " facing and opening " + getFacing();
85  }
86 
87  @Override
88  public Gate clone() {
89  return (Gate) super.clone();
90  }
91 }
void setFacingDirection(BlockFace face)
Definition: Gate.java:29
void setOpen(boolean isOpen)
Definition: Gate.java:70
BlockFace getFacing()
Definition: Gate.java:51