Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
Button.java
1 package org.bukkit.material;
2 
4 import org.bukkit.Material;
5 
6 /**
7  * Represents a button
8  */
9 public class Button extends SimpleAttachableMaterialData implements Redstone {
10  public Button() {
11  super(Material.STONE_BUTTON);
12  }
13 
14  /**
15  *
16  * @deprecated Magic value
17  */
18  @Deprecated
19  public Button(final int type) {
20  super(type);
21  }
22 
23  public Button(final Material type) {
24  super(type);
25  }
26 
27  /**
28  *
29  * @deprecated Magic value
30  */
31  @Deprecated
32  public Button(final int type, final byte data) {
33  super(type, data);
34  }
35 
36  /**
37  *
38  * @deprecated Magic value
39  */
40  @Deprecated
41  public Button(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  * Sets the current state of this button
57  *
58  * @param bool
59  * whether or not the button is powered
60  */
61  public void setPowered(boolean bool) {
62  setData((byte) (bool ? (getData() | 0x8) : (getData() & ~0x8)));
63  }
64 
65  /**
66  * Gets the face that this block is attached on
67  *
68  * @return BlockFace attached to
69  */
71  byte data = (byte) (getData() & 0x7);
72 
73  switch (data) {
74  case 0x1:
75  return BlockFace.WEST;
76 
77  case 0x2:
78  return BlockFace.EAST;
79 
80  case 0x3:
81  return BlockFace.NORTH;
82 
83  case 0x4:
84  return BlockFace.SOUTH;
85  }
86 
87  return null;
88  }
89 
90  /**
91  * Sets the direction this button is pointing toward
92  */
93  public void setFacingDirection(BlockFace face) {
94  byte data = (byte) (getData() & 0x8);
95 
96  switch (face) {
97  case EAST:
98  data |= 0x1;
99  break;
100 
101  case WEST:
102  data |= 0x2;
103  break;
104 
105  case SOUTH:
106  data |= 0x3;
107  break;
108 
109  case NORTH:
110  data |= 0x4;
111  break;
112  }
113 
114  setData(data);
115  }
116 
117  @Override
118  public String toString() {
119  return super.toString() + " " + (isPowered() ? "" : "NOT ") + "POWERED";
120  }
121 
122  @Override
123  public Button clone() {
124  return (Button) super.clone();
125  }
126 }
Button(final int type, final byte data)
Definition: Button.java:32
Button(final Material type, final byte data)
Definition: Button.java:41
BlockFace getAttachedFace()
Definition: Button.java:70
void setPowered(boolean bool)
Definition: Button.java:61
Button(final int type)
Definition: Button.java:19
void setFacingDirection(BlockFace face)
Definition: Button.java:93