Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
Lever.java
1 package org.bukkit.material;
2 
4 import org.bukkit.Material;
5 
6 /**
7  * Represents a lever
8  */
9 public class Lever extends SimpleAttachableMaterialData implements Redstone {
10  public Lever() {
11  super(Material.LEVER);
12  }
13 
14  /**
15  *
16  * @deprecated Magic value
17  */
18  @Deprecated
19  public Lever(final int type) {
20  super(type);
21  }
22 
23  public Lever(final Material type) {
24  super(type);
25  }
26 
27  /**
28  *
29  * @deprecated Magic value
30  */
31  @Deprecated
32  public Lever(final int type, final byte data) {
33  super(type, data);
34  }
35 
36  /**
37  *
38  * @deprecated Magic value
39  */
40  @Deprecated
41  public Lever(final Material type, final byte data) {
42  super(type, data);
43  }
44 
45  /**
46  * Gets the current state of this Material, indicating if it's powered or
47  * unpowered
48  *
49  * @return true if powered, otherwise false
50  */
51  public boolean isPowered() {
52  return (getData() & 0x8) == 0x8;
53  }
54 
55  /**
56  * Set this lever to be powered or not.
57  *
58  * @param isPowered whether the lever should be powered or not
59  */
60  public void setPowered(boolean isPowered) {
61  setData((byte) (isPowered ? (getData() | 0x8) : (getData() & ~0x8)));
62  }
63 
64  /**
65  * Gets the face that this block is attached on
66  *
67  * @return BlockFace attached to
68  */
70  byte data = (byte) (getData() & 0x7);
71 
72  switch (data) {
73  case 0x1:
74  return BlockFace.WEST;
75 
76  case 0x2:
77  return BlockFace.EAST;
78 
79  case 0x3:
80  return BlockFace.NORTH;
81 
82  case 0x4:
83  return BlockFace.SOUTH;
84 
85  case 0x5:
86  case 0x6:
87  return BlockFace.DOWN;
88 
89  case 0x0:
90  case 0x7:
91  return BlockFace.UP;
92 
93  }
94 
95  return null;
96  }
97 
98  /**
99  * Sets the direction this lever is pointing in
100  */
101  public void setFacingDirection(BlockFace face) {
102  byte data = (byte) (getData() & 0x8);
103  BlockFace attach = getAttachedFace();
104 
105  if (attach == BlockFace.DOWN) {
106  switch (face) {
107  case SOUTH:
108  case NORTH:
109  data |= 0x5;
110  break;
111 
112  case EAST:
113  case WEST:
114  data |= 0x6;
115  break;
116  }
117  } else if (attach == BlockFace.UP) {
118  switch (face) {
119  case SOUTH:
120  case NORTH:
121  data |= 0x7;
122  break;
123 
124  case EAST:
125  case WEST:
126  data |= 0x0;
127  break;
128  }
129  } else {
130  switch (face) {
131  case EAST:
132  data |= 0x1;
133  break;
134 
135  case WEST:
136  data |= 0x2;
137  break;
138 
139  case SOUTH:
140  data |= 0x3;
141  break;
142 
143  case NORTH:
144  data |= 0x4;
145  break;
146  }
147  }
148  setData(data);
149  }
150 
151  @Override
152  public String toString() {
153  return super.toString() + " facing " + getFacing() + " " + (isPowered() ? "" : "NOT ") + "POWERED";
154  }
155 
156  @Override
157  public Lever clone() {
158  return (Lever) super.clone();
159  }
160 }
Lever(final int type)
Definition: Lever.java:19
void setFacingDirection(BlockFace face)
Definition: Lever.java:101
Lever(final int type, final byte data)
Definition: Lever.java:32
void setPowered(boolean isPowered)
Definition: Lever.java:60
BlockFace getAttachedFace()
Definition: Lever.java:69
Lever(final Material type, final byte data)
Definition: Lever.java:41