Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
material/Sign.java
1 package org.bukkit.material;
2 
4 import org.bukkit.Material;
5 
6 /**
7  * MaterialData for signs
8  */
9 public class Sign extends MaterialData implements Attachable {
10  public Sign() {
11  super(Material.SIGN_POST);
12  }
13 
14  /**
15  *
16  * @deprecated Magic value
17  */
18  @Deprecated
19  public Sign(final int type) {
20  super(type);
21  }
22 
23  public Sign(final Material type) {
24  super(type);
25  }
26 
27  /**
28  *
29  * @deprecated Magic value
30  */
31  @Deprecated
32  public Sign(final int type, final byte data) {
33  super(type, data);
34  }
35 
36  /**
37  *
38  * @deprecated Magic value
39  */
40  @Deprecated
41  public Sign(final Material type, final byte data) {
42  super(type, data);
43  }
44 
45  /**
46  * Check if this sign is attached to a wall
47  *
48  * @return true if this sign is attached to a wall, false if set on top of
49  * a block
50  */
51  public boolean isWallSign() {
52  return getItemType() == Material.WALL_SIGN;
53  }
54 
55  /**
56  * Gets the face that this block is attached on
57  *
58  * @return BlockFace attached to
59  */
61  if (isWallSign()) {
62  byte data = getData();
63 
64  switch (data) {
65  case 0x2:
66  return BlockFace.SOUTH;
67 
68  case 0x3:
69  return BlockFace.NORTH;
70 
71  case 0x4:
72  return BlockFace.EAST;
73 
74  case 0x5:
75  return BlockFace.WEST;
76  }
77 
78  return null;
79  } else {
80  return BlockFace.DOWN;
81  }
82  }
83 
84  /**
85  * Gets the direction that this sign is currently facing
86  *
87  * @return BlockFace indicating where this sign is facing
88  */
89  public BlockFace getFacing() {
90  byte data = getData();
91 
92  if (!isWallSign()) {
93  switch (data) {
94  case 0x0:
95  return BlockFace.SOUTH;
96 
97  case 0x1:
98  return BlockFace.SOUTH_SOUTH_WEST;
99 
100  case 0x2:
101  return BlockFace.SOUTH_WEST;
102 
103  case 0x3:
104  return BlockFace.WEST_SOUTH_WEST;
105 
106  case 0x4:
107  return BlockFace.WEST;
108 
109  case 0x5:
110  return BlockFace.WEST_NORTH_WEST;
111 
112  case 0x6:
113  return BlockFace.NORTH_WEST;
114 
115  case 0x7:
116  return BlockFace.NORTH_NORTH_WEST;
117 
118  case 0x8:
119  return BlockFace.NORTH;
120 
121  case 0x9:
122  return BlockFace.NORTH_NORTH_EAST;
123 
124  case 0xA:
125  return BlockFace.NORTH_EAST;
126 
127  case 0xB:
128  return BlockFace.EAST_NORTH_EAST;
129 
130  case 0xC:
131  return BlockFace.EAST;
132 
133  case 0xD:
134  return BlockFace.EAST_SOUTH_EAST;
135 
136  case 0xE:
137  return BlockFace.SOUTH_EAST;
138 
139  case 0xF:
140  return BlockFace.SOUTH_SOUTH_EAST;
141  }
142 
143  return null;
144  } else {
145  return getAttachedFace().getOppositeFace();
146  }
147  }
148 
149  public void setFacingDirection(BlockFace face) {
150  byte data;
151 
152  if (isWallSign()) {
153  switch (face) {
154  case NORTH:
155  data = 0x2;
156  break;
157 
158  case SOUTH:
159  data = 0x3;
160  break;
161 
162  case WEST:
163  data = 0x4;
164  break;
165 
166  case EAST:
167  default:
168  data = 0x5;
169  }
170  } else {
171  switch (face) {
172  case SOUTH:
173  data = 0x0;
174  break;
175 
176  case SOUTH_SOUTH_WEST:
177  data = 0x1;
178  break;
179 
180  case SOUTH_WEST:
181  data = 0x2;
182  break;
183 
184  case WEST_SOUTH_WEST:
185  data = 0x3;
186  break;
187 
188  case WEST:
189  data = 0x4;
190  break;
191 
192  case WEST_NORTH_WEST:
193  data = 0x5;
194  break;
195 
196  case NORTH_WEST:
197  data = 0x6;
198  break;
199 
200  case NORTH_NORTH_WEST:
201  data = 0x7;
202  break;
203 
204  case NORTH:
205  data = 0x8;
206  break;
207 
208  case NORTH_NORTH_EAST:
209  data = 0x9;
210  break;
211 
212  case NORTH_EAST:
213  data = 0xA;
214  break;
215 
216  case EAST_NORTH_EAST:
217  data = 0xB;
218  break;
219 
220  case EAST:
221  data = 0xC;
222  break;
223 
224  case EAST_SOUTH_EAST:
225  data = 0xD;
226  break;
227 
228  case SOUTH_SOUTH_EAST:
229  data = 0xF;
230  break;
231 
232  case SOUTH_EAST:
233  default:
234  data = 0xE;
235  }
236  }
237 
238  setData(data);
239  }
240 
241  @Override
242  public String toString() {
243  return super.toString() + " facing " + getFacing();
244  }
245 
246  @Override
247  public Sign clone() {
248  return (Sign) super.clone();
249  }
250 }
Sign(final int type, final byte data)
void setFacingDirection(BlockFace face)
Sign(final Material type, final byte data)