Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
TripwireHook.java
1 package org.bukkit.material;
2 
3 import org.bukkit.Material;
5 
6 /**
7  * Represents the tripwire hook
8  */
9 public class TripwireHook extends SimpleAttachableMaterialData implements Redstone {
10 
11  public TripwireHook() {
12  super(Material.TRIPWIRE_HOOK);
13  }
14 
15  /**
16  *
17  * @deprecated Magic value
18  */
19  @Deprecated
20  public TripwireHook(final int type) {
21  super(type);
22  }
23 
24  /**
25  *
26  * @deprecated Magic value
27  */
28  @Deprecated
29  public TripwireHook(final int type, final byte data) {
30  super(type, data);
31  }
32 
33  public TripwireHook(BlockFace dir) {
34  this();
35  setFacingDirection(dir);
36  }
37 
38  /**
39  * Test if tripwire is connected
40  *
41  * @return true if connected, false if not
42  */
43  public boolean isConnected() {
44  return (getData() & 0x4) != 0;
45  }
46 
47  /**
48  * Set tripwire connection state
49  *
50  * @param connected - true if connected, false if not
51  */
52  public void setConnected(boolean connected) {
53  int dat = getData() & (0x8 | 0x3);
54  if (connected) {
55  dat |= 0x4;
56  }
57  setData((byte) dat);
58  }
59 
60  /**
61  * Test if hook is currently activated
62  *
63  * @return true if activated, false if not
64  */
65  public boolean isActivated() {
66  return (getData() & 0x8) != 0;
67  }
68 
69  /**
70  * Set hook activated state
71  *
72  * @param act - true if activated, false if not
73  */
74  public void setActivated(boolean act) {
75  int dat = getData() & (0x4 | 0x3);
76  if (act) {
77  dat |= 0x8;
78  }
79  setData((byte) dat);
80  }
81 
82  public void setFacingDirection(BlockFace face) {
83  int dat = getData() & 0xC;
84  switch (face) {
85  case WEST:
86  dat |= 0x1;
87  break;
88  case NORTH:
89  dat |= 0x2;
90  break;
91  case EAST:
92  dat |= 0x3;
93  break;
94  case SOUTH:
95  default:
96  break;
97  }
98  setData((byte) dat);
99  }
100 
102  switch (getData() & 0x3) {
103  case 0:
104  return BlockFace.NORTH;
105  case 1:
106  return BlockFace.EAST;
107  case 2:
108  return BlockFace.SOUTH;
109  case 3:
110  return BlockFace.WEST;
111  }
112  return null;
113  }
114 
115  public boolean isPowered() {
116  return isActivated();
117  }
118 
119  @Override
120  public TripwireHook clone() {
121  return (TripwireHook) super.clone();
122  }
123 
124  @Override
125  public String toString() {
126  return super.toString() + " facing " + getFacing() + (isActivated()?" Activated":"") + (isConnected()?" Connected":"");
127  }
128 }
void setConnected(boolean connected)
TripwireHook(final int type, final byte data)
void setFacingDirection(BlockFace face)